Threading the Python interpreter
MooJoo
flossy at bobbsey_twins.com
Mon Feb 18 19:47:40 EST 2008
I've read that the Python interpreter is not thread-safe but are there
any issues in creating threads that create new processes (not threads)
that run new instantiations of python? What I'm doing is subclassing the
threading.Thread and, in the run method, I'm making a call to os.system,
passing to it another python script which then processes a file. When
the call to os.system completes, the thread is finished. Here is a
simplified fragment of code for what I'm doing.
from threading import Thread
import os
class MyThread(Thread):
def __init__(self, fn):
Thread.__init__(self)
self.fn = fn
def run(self):
pyscript = '/usr/bin/env python script.py %s'%self.fn
status = os.system(pyscript)
thr = MyThread('test.dat')
thr.start()
thr.join()
Since I'm running each python instance in a new process, I don't believe
that there is a problem and, in my testing so far, I haven't encountered
anything that would lead me to believe there is a potential time bomb
here. Am I correct in my assumption this is OK or just lucky so far?
More information about the Python-list
mailing list