working Process sample

This commit is contained in:
Olivier R-D 2013-01-11 15:37:29 +01:00
parent fb56ed130c
commit 7f4626445c

34
tracker.py Normal file
View File

@ -0,0 +1,34 @@
import time
from multiprocessing import Process, Queue, Event
class Tracker(Process):
def __init__(self):
self._queue = Queue()
Process.__init__(self, args=(self._queue,))
self._quit = Event()
self._quit.clear()
def run(self):
print("Running")
while not self._quit.is_set():
time.sleep(1)
print("Closing")
def get_result(self):
pass
def shutdown(self):
self._quit.set()
if __name__ == "__main__":
p = Tracker()
try:
p.start()
time.sleep(3)
p.shutdown()
finally:
p.join()