csthread.py

来自「BacNet Simulation Scripts(英文的)。用于数据采集。」· Python 代码 · 共 60 行

PY
60
字号
#! /usr/bin/env python## Filename: CSThread.py"""Module that wraps threads with a name and puts them in a list.  While threads already have a name and there is a way to get a list of the currently active threads (see threading.enumerate()), I needed a way to list of all of them to show the ones that should be running but are not."""import sysimport timeimport threading# some debugging_debug = 0##   CSThread#gThreads = []class Thread(threading.Thread):    def __init__(self,name):        threading.Thread.__init__(self,name=name)        self.threadName = name        gThreads.append(self)    def setName(self,name):        threading.Thread.setName(self,name)        self.threadName = name    def getName(self):        return self.threadNamedef GetThreads():    return gThreadsdef StartThreads():    """When applications initialize the threads have not been started,    this function is called to start them."""    for thread in gThreads:        thread.start()def HaltThreads():    """Stop the threads, it would be nice if they could be started back up."""    for thread in gThreads:        thread.halt()    time.sleep(0.100)def DeadThreads():    """Return a list of the names of threads that have died."""    rslt = []    for thread in gThreads:        if not thread.isAlive():            rslt.append(thread.threadName)    return rslt

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?