[問題] thread無法動作
當我把function丟入queue中時 執行緒跑到
某行就停掉了
當我把main()最下方的time.sleep(10)拿掉時 執行續又開始正常執行
我實在搞不懂為什麼
下方是我的code
def PLCexecute():
while 1:
PLCcontrol()
class OBJthread(threading.Thread):
def __init__(self,queue):
threading.Thread.__init__(self)
self.queue=queue
def run(self):
func,arg=self.queue.get()
if func!=None:
print inspect.getargspec(func)
print inspect.getargspec(func)[0]
if len(inspect.getargspec(func)[0])!=0:
print "argumeents needed"
func(arg)
else:
print "no arguments"<---跑到這邊就停住 有顯示這個字串
func()
self.queue.task_done()
time.sleep(0.5)
self.queue.empty()
def main():
#below part is about the multi-thread
q1=Queue.Queue()
tPLC=OBJthread(q1)
tPLC.setDaemon(True)
tPLC.start()
q1.put((PLCexecute,"hello"))
time.sleep(10)<--comment掉就正常運作...
main()
請教各位了 究竟為何拿掉就正常運作....
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.117.120.110
※ 編輯: wandog 來自: 140.117.120.110 (12/13 20:15)
※ 編輯: wandog 來自: 140.117.120.110 (12/13 20:18)
※ 編輯: wandog 來自: 140.117.120.110 (12/13 20:18)
推
12/13 21:44, , 1F
12/13 21:44, 1F
→
12/13 21:45, , 2F
12/13 21:45, 2F
推
12/13 21:49, , 3F
12/13 21:49, 3F
→
12/13 21:49, , 4F
12/13 21:49, 4F
→
12/13 21:58, , 5F
12/13 21:58, 5F
→
12/13 21:59, , 6F
12/13 21:59, 6F
→
12/13 22:00, , 7F
12/13 22:00, 7F
推
12/13 22:07, , 8F
12/13 22:07, 8F
→
12/13 22:15, , 9F
12/13 22:15, 9F
→
12/14 09:30, , 10F
12/14 09:30, 10F
→
12/14 09:34, , 11F
12/14 09:34, 11F
→
12/14 09:36, , 12F
12/14 09:36, 12F
→
12/14 09:36, , 13F
12/14 09:36, 13F
→
12/14 11:13, , 14F
12/14 11:13, 14F
→
12/14 11:13, , 15F
12/14 11:13, 15F
→
12/14 22:52, , 16F
12/14 22:52, 16F
→
12/14 22:53, , 17F
12/14 22:53, 17F
Python 近期熱門文章
PTT數位生活區 即時熱門文章
18
34