如何在python中停止线程而不停止标志

2024-04-25 19:14:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用python线程处理数据过程。现在当RollingTaskHandler中的run()方法中没有停止信号时,我需要停止已经被sartted的线程。所以我想知道是否有一个直接的方法来停止线程?我指导线程方法并找到一些方法,有人使用这些方法吗?你知道吗

> >>> from threading import Thread
> >>> dir(Thread) ['_Thread__bootstrap', '_Thread__bootstrap_inner', '_Thread__delete', '_Thread__exc_clear', '_Thread__exc_info',
> '_Thread__initialized', '_Thread__stop', '__class__', '__delattr__',
> '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__',
> '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__',
> '__repr__', '__setattr__', '__sizeof__', '__str__',
> '__subclasshook__', '__weakref__', '_block', '_note',
> '_reset_internal_locks', '_set_daemon', '_set_ident', 'daemon',
> 'getName', 'ident', 'isAlive', 'isDaemon', 'is_alive', 'join', 'name',
> 'run', 'setDaemon', 'setName', 'start']



from baymax.views.upgrade import RollingTaskHandler    
 threads=[]
 arg ={...}
 rolling_task_thread = RollingTaskHandler(arg)
 threads.append(rolling_task_thread)


from threading import Thread
class RollingTaskHandler(Thread):

Tags: 方法runfromimportreducebootstrap线程thread