1 Star 0 Fork 1

pish7/stdpython

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
threading_03.py 600 Bytes
一键复制 编辑 原始数据 按行查看 历史
pish7 提交于 2023-10-05 21:56 +08:00 . python
import threading
import time
# 向线程发送信息的辅助类
class StopThread:
def __init__(self):
self.go = True
# 线程类
class ThreadGo(threading.Thread):
def __init__(self, name="", *args, **kargs):
threading.Thread.__init__(self) # 执行父类构造函数
self.args = args
self.kargs = kargs
self.name = name
#重新实现 run 方法
def run(self):
while self.kargs["st"].go:
print("go")
time.sleep(.5)
st = StopThread()
# 创建线程
th = ThreadGo(st=st)
# 启动线程
th.start()
time.sleep(5)
st.go = False
th.join()
print("exit...")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/pish7/stdpython.git
git@gitee.com:pish7/stdpython.git
pish7
stdpython
stdpython
master

搜索帮助