From 7c80ca37fd8823a20ea4b4ceffd7a66b674c785b Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 15 Aug 2016 16:56:00 +0100 Subject: [PATCH] Replace Context lock with code that always runs under GIL --- econtext/core.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/econtext/core.py b/econtext/core.py index 7d4fbc3b..f44c263a 100644 --- a/econtext/core.py +++ b/econtext/core.py @@ -11,6 +11,7 @@ import errno import fcntl import hmac import imp +import itertools import logging import os import random @@ -419,10 +420,8 @@ class Context(object): self.username = username self.key = key or ('%016x' % random.getrandbits(128)) self.parent_addr = parent_addr - - self._last_handle = 1000 + self._last_handle = itertools.count(1000) self._handle_map = {} - self._lock = threading.Lock() def on_shutdown(self): """Slave does nothing, _broker_main() will shutdown its streams.""" @@ -434,12 +433,7 @@ class Context(object): def alloc_handle(self): """Allocate a handle.""" - self._lock.acquire() - try: - self._last_handle += 1 - return self._last_handle - finally: - self._lock.release() + return self._last_handle.next() def add_handle_cb(self, fn, handle, persist=True): """Invoke `fn(obj)` for each `obj` sent to `handle`. Unregister after