execnet-patches / linecache

# HG changeset patch
# Parent da6994ca8402d9d29a367ed312cce0717ea46dad
protect linecache.updatecache with a threading.Lock, fixes #5

diff --git a/execnet/gateway.py b/execnet/gateway.py
--- a/execnet/gateway.py
+++ b/execnet/gateway.py
@@ -6,10 +6,19 @@ gateway code for initiating popen, socke
 import sys, os, inspect, types, linecache
 import textwrap
 import execnet
-from execnet.gateway_base import Message, Popen2IO, serialize
+from execnet.gateway_base import Message, Popen2IO, serialize, threading
 from execnet import gateway_base
 importdir = os.path.dirname(os.path.dirname(execnet.__file__))
 
+linecache_lock = threading.Lock()
+
+def linecache_updatecache(filename):
+    linecache_lock.acquire()
+    try:
+        linecache.updatecache(filename)
+    finally:
+        linecache_lock.release()
+
 class Gateway(gateway_base.BaseGateway):
     """ Gateway to a local or remote Python Intepreter. """
 
@@ -110,7 +119,7 @@ class Gateway(gateway_base.BaseGateway):
         """
         call_name = None
         if isinstance(source, types.ModuleType):
-            linecache.updatecache(inspect.getsourcefile(source))
+            linecache_updatecache(inspect.getsourcefile(source))
             source = inspect.getsource(source)
         elif isinstance(source, types.FunctionType):
             call_name = source.__name__
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.