37,720
社区成员
发帖
与我相关
我的任务
分享
#Transmit and Recive
class TrThread(Thread):
def run(self):
self.doRecv =True
while self.doRecv==True:
rbuf = COM.read(1) #read one, with timeout
if rbuf:
n = COM.inWaiting()
if n:
rbuf = rbuf+COM.read(n)
RQueue.put(rbuf)
root.event_generate("<<COMRxRdy>>",when='tail')
if TQueue:
COM.write(TQueue.get())
time.sleep(0.005)
def stop(self):
self.doRecv = False
trcv=TrThread()
trcv.setDaemon(True)
...
...
...
trcv.stop()
trcv.join()
from threading import *
import time
class MyThread(Thread):
def run (self):
self.ifdo = True;
while self.ifdo:
print 'I am running...'
time.sleep(2)
def stop (self):
print 'I am stopping it...'
self.ifdo = False;
tr = MyThread()
tr.setDaemon(True)
tr.start()
print 'I will stop it...'
time.sleep(5)
tr.stop()
tr.join()
from threading import *
import time
class MyThread(Thread):
def run (self):
self.ifdo = True;
while self.ifdo:
print 'I am running...'
time.sleep(0.1)
def stop (self):
print 'I will stop it...'
self.ifdo = False;
tr = MyThread()
tr.setDaemon(True)
tr.start()
time.sleep(1)
tr.stop()
tr.join()