Ejemplo n.º 1
0
 def __init__(self,
              settings: Dict,
              host: str = '0.0.0.0',
              port: int = 9999):
     super().__init__(settings, host, port)
     self.client_manager = selectors.KqueueSelector()
     # The reason for this set is that every request is handled in its own thread but before
     # the socket is able to be read, control is yeilded to the main thread which picks which sockets are to be read.
     # Since the sub thread hasn't yet exhausted that client socket, the main thread thinks that socket needs to be serviced.
     # So this set prevents that by only servicing client sockets not currently in the set.
     self.clients_currently_being_serviced = set()
     self.clients_to_be_serviced = Queue()
Ejemplo n.º 2
0
 def create_event_loop(self):
     return asyncio.SelectorEventLoop(selectors.KqueueSelector())
Ejemplo n.º 3
0
# date: 2018/10/6

# coroutines
# - Future
# - generator
# - Task

import socket
import time

try:
    import selectors
except ImportError:
    import selectors2 as selectors

selector = selectors.KqueueSelector()
n_task = 0


class Future(object):
    def __init__(self):
        self.callbacks = []

    def resolve(self):
        for cb in self.callbacks:
            cb()


class Task(object):
    def __init__(self, gen):
        self.gen = gen