Skip to content

Instantly share code, notes, and snippets.

@dews
Created November 20, 2018 10:41
Show Gist options
  • Save dews/ca5f1eb1b875958f9aa5011d2da3b94a to your computer and use it in GitHub Desktop.
Save dews/ca5f1eb1b875958f9aa5011d2da3b94a to your computer and use it in GitHub Desktop.
import queue
import time
from threading import Event, Thread
class mo(Thread):
def __init__(self, num, q):
Thread.__init__(self, name='mo' + str(num))
self.num = num
self.q = q
self._stop_event = Event()
def run(self):
# time.sleep(5)
print('runed')
self.run2(self.num)
def run2(self, num):
while True:
time.sleep(1)
self.q.put(num)
print(num)
# def join(self, timeout=None):
# print('join', self.num)
# self._stop_event.set()
# super(mo, self).join(timeout)
def run():
q = queue.Queue(10)
m1 = mo(5,q)
m2 = mo(1,q)
# m1.daemon = True
# m2.daemon = True
m1.start()
m2.start()
# m1.run2(1)
# m2.run2(2)
print(m1)
print(m2)
# m1.join(timeout=2)
# m2.join(timeout=2)
time.sleep(2)
print('run end')
run()
print('Main end')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment