Hi, In the ZShell external method I've written, I've got some code which does the shell globbing for wildcards using the glob.glob module after having redirected some methods from the os module to my own, e.g. : --- CUT --- oldlistdir = os.listdir os.listdir = mylistdir ... glob.glob(...) ... os.listdir = oldlistdir ... --- CUT --- So my question is: is this code thread safe, wrt to other Zope threads accessing the os module methods while they are redirected to mine ? I don't want other Zope threads to access my own methods, just the current one. If it is not thread safe, then how can I do it another way ? Thanks in advance. Jerome Alet - alet@unice.fr
On Wed, 16 May 2001, Jerome Alet wrote:
In the ZShell external method I've written, I've got some code which does the shell globbing for wildcards using the glob.glob module after having redirected some methods from the os module to my own, e.g. :
--- CUT --- oldlistdir = os.listdir os.listdir = mylistdir ... glob.glob(...) ... os.listdir = oldlistdir ... --- CUT ---
So my question is: is this code thread safe, wrt to other Zope threads
Certainly no.
accessing the os module methods while they are redirected to mine ? I don't want other Zope threads to access my own methods, just the current one.
If it is not thread safe, then how can I do it another way ?
Write your own glob(). Or use locks. Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
On Wed, May 16, 2001 at 06:56:53PM +0400, Oleg Broytmann wrote:
accessing the os module methods while they are redirected to mine ? I don't want other Zope threads to access my own methods, just the current one.
If it is not thread safe, then how can I do it another way ?
Write your own glob()
out of question, why rewrite existing free software code ?
. Or use locks.
Please could you be more explicit ? Does zope have a locking mechanism ? bye, Jerome Alet
On Wed, 16 May 2001, Jerome Alet wrote:
. Or use locks.
Please could you be more explicit ? Does zope have a locking mechanism ?
Don't know about Zope locks. But Zope uses Python's threads, so you can easily import threading and aqcuire/release thread locks. Oleg. ---- Oleg Broytmann http://www.zope.org/Members/phd/ phd@phd.pp.ru Programmers don't die, they just GOSUB without RETURN.
On Wed, 16 May 2001 16:44:37 +0200 (MET DST), Jerome Alet <alet@unice.fr> wrote:
So my question is: is this code thread safe, wrt to other Zope threads accessing the os module methods while they are redirected to mine ? I don't want other Zope threads to access my own methods, just the current one.
It is not thread safe
If it is not thread safe, then how can I do it another way ?
What you _really_ want to do is create a duplicate of a module (glob) but providing it with a replacement for a standard module (os). The cheeky solution involves using the standard library module rexec. It was designed for replacing modules in a security sandbox (for example, replacing the standard 'open' function with one that limits access to a specific directory) but it will do exactly what you want too. The python documentation for this module is a little thin, but there is deeper documentation on www.python.org. Toby Dickenson tdickenson@geminidataloggers.com
On Wed, 16 May 2001, Toby Dickenson wrote:
On Wed, 16 May 2001 16:44:37 +0200 (MET DST), Jerome Alet <alet@unice.fr> wrote:
So my question is: is this code thread safe, wrt to other Zope threads accessing the os module methods while they are redirected to mine ? I don't want other Zope threads to access my own methods, just the current one.
The cheeky solution involves using the standard library module rexec. It was designed for replacing modules in a security sandbox (for example, replacing the standard 'open' function with one that limits access to a specific directory) but it will do exactly what you want too.
The python documentation for this module is a little thin, but there is deeper documentation on www.python.org.
I really don't understand how to do that, does someone have working examples ? thanks in advance ! Jerome Alet
On Mon, 21 May 2001 08:40:09 +0200 (MET DST), Jerome Alet <alet@unice.fr> wrote:
On Wed, 16 May 2001, Toby Dickenson wrote:
On Wed, 16 May 2001 16:44:37 +0200 (MET DST), Jerome Alet <alet@unice.fr> wrote:
So my question is: is this code thread safe, wrt to other Zope threads accessing the os module methods while they are redirected to mine ? I don't want other Zope threads to access my own methods, just the current one.
The cheeky solution involves using the standard library module rexec. It was designed for replacing modules in a security sandbox (for example, replacing the standard 'open' function with one that limits access to a specific directory) but it will do exactly what you want too.
The python documentation for this module is a little thin, but there is deeper documentation on www.python.org.
I really don't understand how to do that, does someone have working examples ?
thanks in advance !
import rexec import os def customised_listdir(f): # customise this return ['perl','python','c++'] def make_glob(): r_env = rexec.RExec() module = r_env.add_module('os') for name,value in os.__dict__.items(): setattr(module,name,value) module.listdir = customised_listdir r_env.s_exec('import glob') return r_env.r_eval('glob.glob') glob = make_glob() def test(): print glob('/p*') if __name__=='__main__': test() Toby Dickenson tdickenson@geminidataloggers.com
participants (3)
-
Jerome Alet -
Oleg Broytmann -
Toby Dickenson