在python中是否可以同时连续运行 2个线程?
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 正在调用 运行 方法,该方法是持续 运行 的 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()
我尝试 运行 计算不同数据的线程以及何时调用服务器来提供数据。
我不明白的是为什么线程启动后程序没有传递给调用发送和接收
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 正在调用 运行 方法,该方法是持续 运行 的 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()