working Process sample
This commit is contained in:
parent
fb56ed130c
commit
7f4626445c
34
tracker.py
Normal file
34
tracker.py
Normal 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()
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user