<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
</head>
<body bgcolor="#ffffff" text="#000000">
I'm working on a tool that runs a number of process is separate
thread. <br>
I've, up to this point, been using threading.Thread, but from what I
<br>
read multiprocess will allow multiple processors to be used<br>
From the python docs on multiprocessing.<br>
<Due to this, the multiprocessing module allows the
programmer to fully <br>
leverage multiple processors on a given machine.><br>
<br>
I have run into an issue when modifying the thread object from the
run <br>
method. Threading.thread allows me to change an attribute in the run
method and it hold while multiprocessing.Process loses it.<br>
<br>
Here is an example illustrating the inconsistency that I've seen.<br>
<br>
------------------------------------------------------------------------------<br>
<code><br>
import time<br>
import multiprocessing<br>
import threading<br>
<br>
def simple_process_call():<br>
my_process = SimpleProcess()<br>
my_process.start()<br>
while not my_process.done.is_set():<br>
pass<br>
<br>
print my_process.my_attribute<br>
<br>
class SimpleProcess(multiprocessing.Process):<br>
def __init__(self):<br>
super(SimpleProcess, self).__init__()<br>
self.my_attribute = 'Fail'<br>
self.done = multiprocessing.Event()<br>
<br>
def run(self):<br>
self.my_attribute = 'Success'<br>
time.sleep(5)<br>
self.done.set()<br>
<br>
def simple_thread_call():<br>
my_thread = SimpleThread()<br>
my_thread.start()<br>
while not my_thread.done.is_set():<br>
pass<br>
<br>
print my_thread.my_attribute<br>
<br>
class SimpleThread(threading.Thread):<br>
def __init__(self):<br>
super(SimpleThread, self).__init__()<br>
self.my_attribute = 'Fail'<br>
self.done = threading.Event()<br>
<br>
def run(self):<br>
self.my_attribute = 'Success'<br>
time.sleep(5)<br>
self.done.set()<br>
<br>
if __name__ == '__main__':<br>
# simple_process_call()<br>
simple_thread_call()</code><br>
<br>
<br>
------------------------------------------------------------------------------<br>
<br>
The odd thing is that I can modify the multiprocessing.Event and it
holds, but modifying any attribute on the class goes away. <br>
<br>
If I am super ignorant of something, please cure me of it.<br>
<br>
Thanks in advance!<br>
<br>
<br>
<br>
Brandon L. Harris<br>
<br>
</body>
</html>