[CMF-checkins] CVS: CMF - FSPythonScript.py:1.5
shane@digicool.com
shane@digicool.com
Thu, 12 Apr 2001 15:02:37 -0400 (EDT)
Update of /cvs-repository/CMF/CMFCore
In directory korak:/tmp/cvs-serv28297
Modified Files:
FSPythonScript.py
Log Message:
Correction for thread safety.
--- Updated File FSPythonScript.py in package CMF --
--- FSPythonScript.py 2001/04/11 19:28:09 1.4
+++ FSPythonScript.py 2001/04/12 19:02:35 1.5
@@ -87,6 +87,7 @@
from string import split
from os import path, stat
+import new
import Globals
from AccessControl import ClassSecurityInfo, getSecurityManager
@@ -162,10 +163,19 @@
__traceback_info__ = bound_names, args, kw, self.func_defaults
- if bound_names is not None:
- # Updating func_globals directly *should* be thread-safe.
- f.func_globals.update(bound_names)
-
+ if bound_names:
+ # Updating func_globals directly is not thread safe here.
+ # In normal PythonScripts, every thread has its own
+ # copy of the function. But in FSPythonScripts
+ # there is only one copy. So here's another way.
+ new_globals = f.func_globals.copy()
+ new_globals.update(bound_names)
+ if f.func_defaults:
+ f = new.function(f.func_code, new_globals, f.func_name,
+ f.func_defaults)
+ else:
+ f = new.function(f.func_code, new_globals, f.func_name)
+
# Execute the function in a new security context.
security=getSecurityManager()
security.addContext(self)