예제 #1
0
    def __init__(self, threadpool):
        # Construct in the main thread (owner of the threadpool)
        # The parent greenlet and thread identifier will be set once the
        # new thread begins running.
        RawGreenlet.__init__(self)

        self._hub = threadpool.hub
        # Avoid doing any imports in the background thread if it's not
        # necessary (monkey.get_original imports if not patched).
        # Background imports can hang Python 2 (gevent's thread resolver runs in the BG,
        # and resolving may have to import the idna module, which needs an import lock, so
        # resolving at module scope)
        if monkey.is_module_patched('sys'):
            stderr = monkey.get_original('sys', 'stderr')
        else:
            stderr = sys.stderr
        self._stderr = stderr
        # We can capture the task_queue; even though it can change if the threadpool
        # is re-innitted, we won't be running in that case
        self._task_queue = threadpool.task_queue  # type:gevent._threading.Queue
        self._task_queue_cookie = self._task_queue.allocate_cookie()
        self._unregister_worker = threadpool._unregister_worker

        threadpool._register_worker(self)
        try:
            start_new_thread(self._begin, ())
        except:
            self._unregister_worker(self)
            raise
예제 #2
0
파일: util.py 프로젝트: mwhooker/kazoo
def thread(func):
    """Thread decorator

    Takes a function and spawns it as a daemon thread using the
    real OS thread regardless of monkey patching.

    """
    start_new_thread(func, ())
예제 #3
0
 def _add_thread(self):
     with self._lock:
         self._size += 1
     try:
         start_new_thread(self._worker, ())
     except:
         with self._lock:
             self._size -= 1
         raise
예제 #4
0
 def _add_thread(self):
     with self._lock:
         self._size += 1
     try:
         start_new_thread(self._worker, ())
     except:
         with self._lock:
             self._size -= 1
         raise
예제 #5
0
 def _add_thread(self):
     with self._lock:
         self._size += 1
     try:
         start_new_thread(self.__trampoline, ())
     except:
         with self._lock:
             self._size -= 1
         raise
예제 #6
0
파일: threadpool.py 프로젝트: gevent/gevent
 def _add_thread(self):
     with self._lock:
         self._size += 1
     try:
         start_new_thread(self.__trampoline, ())
     except:
         with self._lock:
             self._size -= 1
         raise
예제 #7
0
파일: channels.py 프로젝트: mguijarr/bliss
    def __init__(self, redis, bus_id, channels_bus_list):   
        self._id = bus_id

        # create socket
        self._bus_socket = nanomsg.Socket(nanomsg.BUS)

        bus_socket_port_number = get_free_port(redis,CHANNELS_BUS)
        self._bus_socket.bind("tcp://*:%d" % bus_socket_port_number)
        BUS_BY_FD[self.recv_fd] = self
        # connect to other bus sockets     
        for remote_bus in channels_bus_list:
            self._bus_socket.connect(remote_bus)
        self.__bus_addr = "tcp://%s:%d" % (socket.getfqdn(), bus_socket_port_number)

        # remove address in redis at exit
        atexit.register(_clean_redis, redis, self.addr)

        # receiver thread takes care of dispatching received values to right channels
        global RECEIVER_THREAD
        if RECEIVER_THREAD is None:
            global WAKE_UP_SOCKET_W
            global WAKE_UP_SOCKET_R
            WAKE_UP_SOCKET_W = nanomsg.Socket(nanomsg.PAIR)
            WAKE_UP_SOCKET_W.bind("inproc://beacon/channels/wake_up_loop")
            WAKE_UP_SOCKET_R = nanomsg.Socket(nanomsg.PAIR)
            WAKE_UP_SOCKET_R.connect("inproc://beacon/channels/wake_up_loop")
            RECEIVER_THREAD = threading.start_new_thread(receive_channels_values, ()) 
            atexit.register(stop_receiver_thread)
        else:
            WAKE_UP_SOCKET_W.send('!')
예제 #8
0
    def __init__(self):
        self.setting_names = ["velocity", "position", "dial_position", "_set_position", "state",
                              "offset", "acceleration", "low_limit", "high_limit"]
        from bliss.common import axis
        self.convert_funcs = {
            "velocity": float,
            "position": float,
            "dial_position": float,
            "_set_position": float,
            "state": axis.AxisState,
            "offset": float,
            "low_limit": float,
            "high_limit": float,
            "acceleration": float}
        self.axis_settings_dict = dict()

        from bliss.config import motors as config
        global SETTINGS_WRITER_THREAD
        global SETTINGS_WRITER_QUEUE
        global SETTINGS_WRITER_WATCHER
        if SETTINGS_WRITER_THREAD is None:
            if config.BACKEND == 'xml':
                SETTINGS_WRITER_QUEUE = _threading.Queue()
                SETTINGS_WRITER_WATCHER = _threading.Event()
                SETTINGS_WRITER_WATCHER.set()
                atexit.register(wait_settings_writing)
                if SETTINGS_WRITER_THREAD is None:
                    SETTINGS_WRITER_THREAD = _threading.start_new_thread(
                        write_settings, ())
            else:
                SETTINGS_WRITER_QUEUE = gevent.queue.Queue()
                SETTINGS_WRITER_WATCHER = gevent.event.Event()
                SETTINGS_WRITER_WATCHER.set()
                if SETTINGS_WRITER_THREAD is None:
                    SETTINGS_WRITER_THREAD = gevent.spawn(write_settings)
예제 #9
0
def check_gevent_thread():
    global gevent_thread

    if gevent_thread is None:
        with gevent_thread_lock:
            gevent_thread = _threading.start_new_thread(
                process_requests, (main_queue,))

    gevent_thread_started.wait()
예제 #10
0
def check_gevent_thread():
    global gevent_thread

    if gevent_thread is None:
        with gevent_thread_lock:
            gevent_thread = _threading.start_new_thread(
                process_requests, (main_queue, ))

    gevent_thread_started.wait()
예제 #11
0
    def start(self):
        """Start the thread."""
        from gevent._threading import start_new_thread

        self.quit = False
        self.has_quit = False
        threading._limbo[self] = self
        try:
            self._tident = start_new_thread(self.run, tuple())
        except Exception:
            del threading._limbo[self]
        PERIODIC_THREAD_IDS.add(self._tident)
예제 #12
0
    def __init__(self, redis, bus_id, channels_bus_list):
        self._id = bus_id

        # create sockets
        self._bus_socket = nanomsg.Socket(nanomsg.BUS)
        self._respondent_socket = nanomsg.Socket(nanomsg.RESPONDENT)

        bus_socket_port_number = get_free_port(redis, CHANNELS_BUS)
        self._bus_socket.bind("tcp://*:%d" % bus_socket_port_number)
        BUS_BY_FD[self.recv_fd] = self
        # connect to other bus sockets
        for remote_bus in channels_bus_list:
            self._bus_socket.connect(remote_bus)
        self.__bus_addr = "tcp://%s:%d" % (socket.getfqdn(),
                                           bus_socket_port_number)

        # respondent socket is used to reply to survey requests
        respondent_socket_port_number = get_free_port(redis,
                                                      CHANNELS_RESPONDENT)
        self._respondent_socket.bind("tcp://*:%d" %
                                     respondent_socket_port_number)
        BUS_BY_FD[self._respondent_socket.recv_fd] = self
        self.__bus_respondent_addr = "tcp://%s:%d" % (
            socket.getfqdn(), respondent_socket_port_number)

        # remove addresses in redis at exit
        atexit.register(_clean_redis, redis, self.addr, self.respondent_addr)

        # receiver thread takes care of dispatching received values to right channels
        global RECEIVER_THREAD
        if RECEIVER_THREAD is None:
            global WAKE_UP_SOCKET_W
            global WAKE_UP_SOCKET_R
            WAKE_UP_SOCKET_W = nanomsg.Socket(nanomsg.PAIR)
            WAKE_UP_SOCKET_W.bind("inproc://beacon/channels/wake_up_loop")
            WAKE_UP_SOCKET_R = nanomsg.Socket(nanomsg.PAIR)
            WAKE_UP_SOCKET_R.connect("inproc://beacon/channels/wake_up_loop")
            RECEIVER_THREAD = threading.start_new_thread(
                receive_channels_values, ())
            atexit.register(stop_receiver_thread)
        else:
            WAKE_UP_SOCKET_W.send('!')
예제 #13
0
 def start_delayed(self, delay):
     self.delay = delay
     _threading.start_new_thread(self.run, ())  # self.start()
예제 #14
0
 def start_delayed(self, delay):
     self.delay = delay
     _threading.start_new_thread(self.run, ()) #self.start()