foreve结束

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import asyncio
from threading import Thread
import time
 
print('main start:',time.time())
 
async def start(i):
    print(i, time.time())
    await asyncio.sleep(i)
    b=run(i)
    if b is not None:
        await asyncio.wait(b)
    else:
        print('all complete',time.time())
        return True
 
def run(content):
    if content<3:
        tasks=[]
        tasks.append(start(content+1))
        tasks.append(start(content+1))
        tasks.append(start(content+1))
        return tasks
    print('end running', time.time())
 
def start_loop(loop):
    asyncio.set_event_loop(loop)
    loop.run_forever()
 
new_loop=asyncio.new_event_loop()
t=Thread(target=start_loop,args=(new_loop,))
t.start()
 
a=asyncio.run_coroutine_threadsafe(start(1),new_loop)
 
while a._state !='FINISHED':
    time.sleep(1)
    print(a._state)
 
print(new_loop.is_closed(),'checking')
new_loop.stop()
new_loop._csock.send(b'\0')
print(new_loop.is_closed(),'checking')

  

posted @   CrossPython  阅读(154)  评论(0)    收藏  举报
编辑推荐:
· 记一次 .NET某云HIS系统 CPU爆高分析
· 如果单表数据量大,只能考虑分库分表吗?
· 一文彻底搞懂 MCP:AI 大模型的标准化工具箱
· 电商平台中订单未支付过期如何实现自动关单?
· 用 .NET NativeAOT 构建完全 distroless 的静态链接应用
阅读排行:
· 一款让 Everything 更加如虎添翼的 .NET 开源辅助工具!
· (原创)[开源][.Net Framework 4.5] SimpleMVVM(极简MVVM框架)更
· 干货分享!MCP 实现原理,小白也能看懂
· 精选 4 款免费且实用的数据库管理工具,程序员必备!
· Cursor:一个让程序员“失业”的AI代码搭子
点击右上角即可分享
微信分享提示