Ejemplo n.º 1
0
    def _listeners_for_thread(self):
        """All Listeners for the current thread"""

        thread = get_thread_ident()
        with self.lock:
            return [
                l for m in self.listeners.values() for (tid, l) in m.items()
                if tid == thread
            ]
Ejemplo n.º 2
0
 def add_listener(self, event_type, callback):
     """Add a listener for specific event type.
     You'll need to actually listen for changes using the listen method"""
     if event_type not in EVENT_TYPES:
         raise ValueError("Invalid event type: {}".format(event_type))
     thread = get_thread_ident()
     with self.lock:
         listener = self.listeners[event_type][thread]
     listener.add(callback)
     if event_type == "file":
         for file in self.room.files:
             self.enqueue_data(event_type, file)
     self.process_queues()
Ejemplo n.º 3
0
def _common_request_extra_log_context():
    return {
        "method": request.method,
        "url": request.url,
        "endpoint": request.endpoint,
        # pid and thread ident are both available on LogRecord by default, as `process` and `thread`
        # respectively but I don't see a straightforward way of selectively including them only in certain
        # log messages - they are designed to be included when the formatter is being configured. This is why
        # I'm manually grabbing them and putting them in as `extra` here, avoiding the existing parameter names
        # to prevent LogRecord from complaining
        "process_": getpid(),
        # stringifying this as it could potentially be a long that json is unable to represent accurately
        "thread_": str(get_thread_ident()),
    }
Ejemplo n.º 4
0
    def add_listener(self, event_type, callback):
        """Add a listener for specific event type.
        You'll need to actually listen for changes using the listen method"""

        if not self.connected:
            raise ValueError("Room is not connected")
        thread = get_thread_ident()
        with self.lock:
            listener = self.listeners[event_type][thread]
        listener.add(callback)
        if event_type == "file":
            for file in self.room.files:
                self.enqueue_data(event_type, file)
        self.process_queues()
Ejemplo n.º 5
0
    def add_listener(self, event_type, callback):
        """Add a listener for specific event type.
        You'll need to actually listen for changes using the listen method"""

        if not self.connected:
            # wait for errors set by reraise method
            time.sleep(1)
            if self.exception:
                # pylint: disable=raising-bad-type
                raise self.exception
            raise ConnectionError(self.room + " is not connected")

        thread = get_thread_ident()
        with self.lock:
            listener = self.listeners[thread]
        listener.add(event_type, callback)
        # use "initial_files" event to listen for whole filelist on room join
        self.process_queues()
Ejemplo n.º 6
0
 def handler(self, sig, current_frame):
     if self.stopping:
         # Told to stop, cancel timer and return
         timer = self.mode.value[0]
         signal.setitimer(timer, 0, 0)
         self.running = False
     else:
         current_tid = get_thread_ident()
         for tid, frame in sys._current_frames().items():
             if tid == current_tid:
                 frame = current_frame
             frames = []
             while frame is not None:
                 code = frame.f_code
                 frames.append(
                     (code.co_filename, code.co_firstlineno, code.co_name))
                 frame = frame.f_back
             self.stacks.append(frames)
Ejemplo n.º 7
0
 def _listeners_for_thread(self):
     """All Listeners for the current thread"""
     thread = get_thread_ident()
     with self.lock:
         return [l for m in self.listeners.values()
                 for (tid, l) in m.items() if tid == thread]
Ejemplo n.º 8
0
 def __init__(self):
     if get_thread_ident() == cothread.scheduler_thread_id:
         self._event_queue = cothread.EventQueue()
     else:
         self._event_queue = cothread.ThreadedEventQueue()