[英]Is it possible to run 2 threads in the same time continuously in python?
我嘗試運行一個計算不同數據的線程,以及何時調用服務器來提供數據。
我不明白的是為什么程序在線程啟動后不通過調用發送和接收
class FuncThread(threading.Thread):
def __init__(self, image_model):
self.image_model = image_model
threading.Thread.__init__(self)
def run(self):
image_model = self.image_model
while True:
def sending_ receiving():
while true:
image_model = init()
thread1 = FuncThread(image_model)
thread1.setDaemon(True)
thread1.start() # this should not affect the course of executing order
sending_and_reciveing() - this is contiuously listening client request
thread.start 正在調用 run 方法,該方法是一個持續運行的 while true 循環。
如果我更正代碼中的拼寫錯誤,它在我的機器上運行良好。
import time
import threading
class FuncThread(threading.Thread):
def __init__(self, image_model):
self.image_model = image_model
threading.Thread.__init__(self)
def run(self):
image_model = self.image_model
while True:
print('run')
time.sleep(1)
def sending_and_receiving():
while True:
print('sending_and_receiving')
time.sleep(1)
image_model = 'test'
thread1 = FuncThread(image_model)
thread1.setDaemon(True)
thread1.start()
sending_and_receiving()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.