|
|
@ -11,6 +11,7 @@ import errno
|
|
|
|
import fcntl
|
|
|
|
import fcntl
|
|
|
|
import hmac
|
|
|
|
import hmac
|
|
|
|
import imp
|
|
|
|
import imp
|
|
|
|
|
|
|
|
import itertools
|
|
|
|
import logging
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import os
|
|
|
|
import random
|
|
|
|
import random
|
|
|
@ -419,10 +420,8 @@ class Context(object):
|
|
|
|
self.username = username
|
|
|
|
self.username = username
|
|
|
|
self.key = key or ('%016x' % random.getrandbits(128))
|
|
|
|
self.key = key or ('%016x' % random.getrandbits(128))
|
|
|
|
self.parent_addr = parent_addr
|
|
|
|
self.parent_addr = parent_addr
|
|
|
|
|
|
|
|
self._last_handle = itertools.count(1000)
|
|
|
|
self._last_handle = 1000
|
|
|
|
|
|
|
|
self._handle_map = {}
|
|
|
|
self._handle_map = {}
|
|
|
|
self._lock = threading.Lock()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_shutdown(self):
|
|
|
|
def on_shutdown(self):
|
|
|
|
"""Slave does nothing, _broker_main() will shutdown its streams."""
|
|
|
|
"""Slave does nothing, _broker_main() will shutdown its streams."""
|
|
|
@ -434,12 +433,7 @@ class Context(object):
|
|
|
|
|
|
|
|
|
|
|
|
def alloc_handle(self):
|
|
|
|
def alloc_handle(self):
|
|
|
|
"""Allocate a handle."""
|
|
|
|
"""Allocate a handle."""
|
|
|
|
self._lock.acquire()
|
|
|
|
return self._last_handle.next()
|
|
|
|
try:
|
|
|
|
|
|
|
|
self._last_handle += 1
|
|
|
|
|
|
|
|
return self._last_handle
|
|
|
|
|
|
|
|
finally:
|
|
|
|
|
|
|
|
self._lock.release()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_handle_cb(self, fn, handle, persist=True):
|
|
|
|
def add_handle_cb(self, fn, handle, persist=True):
|
|
|
|
"""Invoke `fn(obj)` for each `obj` sent to `handle`. Unregister after
|
|
|
|
"""Invoke `fn(obj)` for each `obj` sent to `handle`. Unregister after
|
|
|
|