我有一个thread类,在其中,我想创建一个thread函数来正确地处理thread实例。有可能吗?如果有,怎么可能?你知道吗
thread类的run函数每隔x秒执行一个作业。我想创建一个线程函数来执行与run函数并行的任务。你知道吗
class Concurrent(threading.Thread):
def __init__(self,consType, consTemp):
# something
def run(self):
# make foo as a thread
def foo (self):
# something
如果没有,想想下面的情况,有没有可能,怎么可能?你知道吗
class Concurrent(threading.Thread):
def __init__(self,consType, consTemp):
# something
def run(self):
# make foo as a thread
def foo ():
# something
如果不清楚,请告诉我。我会试着重新编辑
只需启动另一个线程。您已经知道如何创建和启动它们,所以只需编写另一个子类
Thread
和start()
就可以了。你知道吗用
run()
而不是foo()
更改def foo()
子类的Thread
。你知道吗首先,我建议您重新考虑使用线程。在大多数情况下,在Python中应该使用multiprocessing。。这是因为Python的GIL。
除非您使用的是Jython或IronPython。
如果我理解正确,只需在已打开的线程中打开另一个线程:
程序输出为:
相关问题 更多 >
编程相关推荐