コード例 #1
0
ファイル: tpool.py プロジェクト: SMFOSS/gevent
    def __init__(self, poolsize=20):
        self.poolsize = poolsize
        self.thread_list = []
        self.q = tlmonkey.run_with_unpatched(Queue.Queue)

        for x in range(poolsize):
            t = threading.Thread(target=self._work)
            t.setDaemon(True)
            t.start()
            self.thread_list.append(t)
コード例 #2
0
ファイル: tpool.py プロジェクト: SMFOSS/gevent
from gevent import tlmonkey

threading = tlmonkey.import_unpatched("threading")


# Simple wrapper to os.pipe() - but sets to non-block
def _pipe():
    r, w = os.pipe()
    fcntl.fcntl(r, fcntl.F_SETFL, os.O_NONBLOCK)
    fcntl.fcntl(w, fcntl.F_SETFL, os.O_NONBLOCK)
    return r, w


_core_pipe_read, _core_pipe_write = _pipe()

_hubq = tlmonkey.run_with_unpatched(Queue.Queue)


def _core_pipe_read_callback(event, evtype):
    try:
        os.read(event.fd, 1)
    except EnvironmentError:
        pass

    while 1:
        try:
            f, args, kwargs = _hubq.get(block=False)
        except Queue.Empty:
            return
        try:
            f(*args, **kwargs)