1 Star 0 Fork 1

pish7/stdpython

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

搜索帮助