Skip to content

Commit

Permalink
The import module lock is popeed from the wref callback instead of del,
Browse files Browse the repository at this point in the history
This avoids a printed/ignored KeyError seen on PyPy/arm. [skip ci]
  • Loading branch information
jamadden committed Feb 16, 2016
1 parent e93f0e0 commit 8ff9ee5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions gevent/builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@

def __module_lock(name):
# Return the lock for the given module, creating it if necessary.
# It will be removed when no longer needed
# It will be removed when no longer needed.
# Nothing in this function yields, so we're multi-greenlet safe
# (But not multi-threading safe.)
# XXX: What about on PyPy, where the GC is asynchronous (not ref-counting)?
# (Does it stop-the-world first?)
lock = None
try:
lock = _g_import_locks[name]()
Expand All @@ -56,7 +60,8 @@ def __module_lock(name):
lock = RLock()

def cb(_):
del _g_import_locks[name]
# We've seen a KeyError on PyPy on RPi2
_g_import_locks.pop(name, None)
_g_import_locks[name] = weakref.ref(lock, cb)
return lock

Expand Down

0 comments on commit 8ff9ee5

Please sign in to comment.