Polling loop for events from other threads
346703
def timer_fired(self):
        """"""
        self.__process_idle_events()

        # grab the simulation lock, gather all of the
        # wpilib objects, and display them on the screen
        self.update_widgets()

        # call next timer_fired (or we'll never call timer_fired again!)
        delay = 100  # milliseconds
        self.root.after(delay, self.timer_fired)
1142907
def Handle_Events(self, events):
        
        for e in events:

            sock = e[0]
            event_type = e[1]

            if event_type == zmq.POLLIN:
                msg = sock.recv()
                reply = self.Handle_Receive(msg)
                sock.send(reply)
            elif event_type == zmq.POLLOUT:
                pass  # FIXME -- handle this correctly
            elif event_type == zmq.POLLERR:
                pass  # FIXME -- handle this correctly
            else:
                pass
1347883
def current(cls):
        
        try:
            return _tls.loop
        except AttributeError:
            # create loop only for main thread
            if threading.current_thread().name == 'MainThread':
                _tls.loop = cls()
                return _tls.loop
            raise RuntimeError('there is no event loop created in the current thread')
996459
def polling_loop(connection)
      if polling?
        polling_msg = "Polling enabled. Checking every #{config.poll_interval} seconds."
      else
        polling_msg = "Polling disabled. Checking for messages once."
      end
      Mailman.logger.info(polling_msg)

      tries ||= 5
      loop do
        begin
          connection.connect
          connection.get_messages
        rescue SystemCallError, EOFError => e
          Mailman.logger.error e.message
          unless (tries -= 1).zero?
            Mailman.logger.error "Retrying..."
            begin
              connection.disconnect
            rescue # don't crash in the crash handler
            end
            retry
          end
        ensure
          connection.started? && connection.disconnect
        end

        break unless polling?
        sleep config.poll_interval
      end
    end
1091512
def _on_io_events(self, fd=None, _events=None):
        
        if fd not in self._connections:
            LOGGER.warning('Received IO event for non-existing connection')
            return
        self._poll_connection(fd)
198730
def __postCallAction(self, event):
        
        aThread = event.get_thread()
        retval  = self._get_return_value(aThread)
        self.__callHandler(self.__postCB, event, retval)
107177
def _handle_events(self, fd: int, events: int) -> None:
        
        action = 0
        if events & ioloop.IOLoop.READ:
            action |= pycurl.CSELECT_IN
        if events & ioloop.IOLoop.WRITE:
            action |= pycurl.CSELECT_OUT
        while True:
            try:
                ret, num_handles = self._multi.socket_action(fd, action)
            except pycurl.error as e:
                ret = e.args[0]
            if ret != pycurl.E_CALL_MULTI_PERFORM:
                break
        self._finish_pending_requests()
631583
def _polling_iteration(self):
		
		if self.__task is None:
			self.ready_event().set()
		elif self.__task.check_events() is True:
			self.ready_event().set()
			self.registry().task_finished(self)
880650
def _polling_iteration(self):
		
		if len(self.__task_chain) > 0:
			if self.__current_task is None:
				self.__current_task = 0

			task = self.__task_chain[self.__current_task]
			if task.thread() is None:
				task.start()
			elif task.ready_event().is_set() is True:
				task.stop()
				if self.__current_task < (len(self.__task_chain) - 1):
					self.__current_task += 1
				else:
					self.ready_event().set()
			elif task.exception_event().is_set() is True:
				raise RuntimeError('Child thread failed')
		else:
			self.ready_event().set()
966870
def trigger(self, event: str, **kwargs: Any) -> None:
        """"""
        event = event.upper()
        for func in self._event_handlers[event]:
            self.loop.create_task(func(**kwargs))
        # This will unblock anyone that is awaiting on the next loop update,
        # while still ensuring the next `await client.wait(event)` doesn't
        # immediately fire.
        async_event = self._events[event]
        async_event.set()
        async_event.clear()
1007655
def begin_stream_loop(stream, poll_interval):
    """"""
    while should_continue():
        try:
            stream.start_polling(poll_interval)
        except Exception as e:
            # Infinite restart
            logger.error("Exception while polling. Restarting in 1 second.", exc_info=True)
            time.sleep(1)
562689
protected void poll() {
        int missCount = 0;
        String curQueue = null;
        while (RUNNING.equals(this.state.get())) {
            try {
                if (threadNameChangingEnabled) {
                    renameThread("Waiting for " + JesqueUtils.join(",", this.queueNames));
                }
                curQueue = getNextQueue();
                if (curQueue != null) {
                    checkPaused();
                    // Might have been waiting in poll()/checkPaused() for a while
                    if (RUNNING.equals(this.state.get())) {
                        this.listenerDelegate.fireEvent(WORKER_POLL, this, curQueue, null, null, null, null);
                        final String payload = pop(curQueue);
                        if (payload != null) {
                            process(ObjectMapperFactory.get().readValue(payload, Job.class), curQueue);
                            missCount = 0;
                        } else {
                            missCount++;
                            if (shouldSleep(missCount) && RUNNING.equals(this.state.get())) {
                                // Keeps worker from busy-spinning on empty queues
                                missCount = 0;
                                Thread.sleep(EMPTY_QUEUE_SLEEP_TIME);
                            }
                        }
                    }
                }
            } catch (InterruptedException ie) {
                if (!isShutdown()) {
                    recoverFromException(curQueue, ie);
                }
            } catch (JsonParseException | JsonMappingException e) {
                // If the job JSON is not deserializable, we never want to submit it again...
                removeInFlight(curQueue, true);
                recoverFromException(curQueue, e);
            } catch (Exception e) {
                recoverFromException(curQueue, e);
            }
        }
    }
499939
def __process_idle_events(self):
        """"""
        while True:
            try:
                callable, args = self.queue.get(block=False)
            except queue.Empty:
                break
            callable(*args)
730517
def poll(self):
        """"""
        queue_empty = self.server.get_queue_empty_exception()
        try:
            packets = [self.queue.get(timeout=self.server.ping_timeout)]
            self.queue.task_done()
        except queue_empty:
            raise exceptions.QueueEmpty()
        if packets == [None]:
            return []
        while True:
            try:
                packets.append(self.queue.get(block=False))
                self.queue.task_done()
            except queue_empty:
                break
        return packets
278518
def process_events(self):
        """"""
        for event, args in iter_except(self.event_queue.popleft, IndexError):
            for callback in self.event_callbacks[event]:
                callback(*args)
165709
def event_loop(self):
        
        if hasattr(self.loop, '._run_once'):
            self.loop._thread_id = threading.get_ident()
            try:
                self.loop._run_once()
            finally:
                self.loop._thread_id = None
        else:
            self.loop.call_soon(self.loop.stop)
            self.loop.run_forever()
291749
def _events(self):
    """"""
    for did, device in sorted(six.iteritems(self._proto.devices)):
      if device.name:
        yield dict(
            ph=_TYPE_METADATA,
            pid=did,
            name='process_name',
            args=dict(name=device.name))
      yield dict(
          ph=_TYPE_METADATA,
          pid=did,
          name='process_sort_index',
          args=dict(sort_index=did))
      for rid, resource in sorted(six.iteritems(device.resources)):
        if resource.name:
          yield dict(
              ph=_TYPE_METADATA,
              pid=did,
              tid=rid,
              name='thread_name',
              args=dict(name=resource.name))
        yield dict(
            ph=_TYPE_METADATA,
            pid=did,
            tid=rid,
            name='thread_sort_index',
            args=dict(sort_index=rid))
    # TODO(sammccall): filtering and downsampling?
    for event in self._proto.trace_events:
      yield self._event(event)