如何让线程在Python中运行?
我可以用我的代码调用类实例,但似乎无法将其用于多线程。看起来线程没有启动,即使它们是活动的 我已经阅读了关于线程的文档,尝试使用super()等 输出为:如何让线程在Python中运行?,python,multithreading,class,Python,Multithreading,Class,我可以用我的代码调用类实例,但似乎无法将其用于多线程。看起来线程没有启动,即使它们是活动的 我已经阅读了关于线程的文档,尝试使用super()等 输出为: <bound method Thread.is_alive of <Dashboard(Thread-1, stopped 123145347162112)>> <bound method Thread.is_alive of <Dashboard(Thread-2, stopped 12314534716
<bound method Thread.is_alive of <Dashboard(Thread-1, stopped 123145347162112)>>
<bound method Thread.is_alive of <Dashboard(Thread-2, stopped 123145347162112)>>
您没有给超类构造函数提供任何参数,这意味着目标是
None
假设调用screen1.start()
时希望执行instance()
方法,请尝试以下操作:
super().__init__(target=self.instance)
另外,您可能希望调用
is_alive
方法,而不是打印其签名。您没有给超类构造函数提供任何参数,这意味着目标是None
假设调用screen1.start()
时希望执行instance()
方法,请尝试以下操作:
super().__init__(target=self.instance)
另外,您可能希望调用
is_alive
方法,而不是打印其签名。您需要调用is_alive
方法:
print(screen1.is_alive())
另外,在线程
子类仪表板
中不重写运行
,因此当调用启动
时,它们什么也不做。也许您希望运行实例
,如果是这样,请将其命名为运行
:
def run(self):
或者让
运行
调用它。您需要调用处于活动状态
方法:
print(screen1.is_alive())
另外,在线程
子类仪表板
中不重写运行
,因此当调用启动
时,它们什么也不做。也许您希望运行实例
,如果是这样,请将其命名为运行
:
def run(self):
或者让
运行
调用它。我找到了答案。我只需将def实例重命名为def run:我就知道了。我只需将def实例重命名为def run: