def __init__(self, n=1):
sync = thread.allocate_lock()
self._acquire = sync.acquire
self._release = sync.release
pool = []
self._lists = (
pool, # Collection of locks representing threads are not
# waiting for work to do
[], # Request queue
[], # Pool of locks representing threads that are
# waiting (ready) for work to do.
)
self._acquire() # callers will block
try:
while n > 0:
l = thread.allocate_lock()
l.acquire()
pool.append(l)
thread.start_new_thread(ZServerPublisher,
(self.accept,))
n = n - 1
finally:
self._release() # let callers through now
评论列表
文章目录