Commit 9cf889b8 authored by David Wilson's avatar David Wilson

issue #144: master: public/private Pool attributes.

parent 19632473
...@@ -87,32 +87,34 @@ class Service(object): ...@@ -87,32 +87,34 @@ class Service(object):
class Pool(object): class Pool(object):
def __init__(self, router, services, size=1): def __init__(self, router, services, size=1):
self.router = router
self.services = list(services) self.services = list(services)
self.select = mitogen.master.Select( self.size = size
self._select = mitogen.master.Select(
receivers=[ receivers=[
service.recv service.recv
for service in self.services for service in self.services
], ],
oneshot=False, oneshot=False,
) )
self.threads = [] self._threads = []
for x in xrange(size): for x in xrange(size):
thread = threading.Thread( thread = threading.Thread(
name='mitogen.service.Pool.worker-%d' % (x,), name='mitogen.service.Pool.worker-%d' % (x,),
target=self._worker_main, target=self._worker_main,
) )
thread.start() thread.start()
self.threads.append(thread) self._threads.append(thread)
def stop(self): def stop(self):
self.select.close() self._select.close()
for th in self.threads: for th in self._threads:
th.join() th.join()
def _worker_main(self): def _worker_main(self):
while True: while True:
try: try:
msg = self.select.get() msg = self._select.get()
except (mitogen.core.ChannelError, mitogen.core.LatchError): except (mitogen.core.ChannelError, mitogen.core.LatchError):
e = sys.exc_info()[1] e = sys.exc_info()[1]
LOG.error('%r: channel or latch closed, exitting: %s', self, e) LOG.error('%r: channel or latch closed, exitting: %s', self, e)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment