Created
November 20, 2018 10:41
-
-
Save dews/ca5f1eb1b875958f9aa5011d2da3b94a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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