-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstruct_aspzem.py
51 lines (40 loc) · 1.14 KB
/
struct_aspzem.py
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
44
45
46
47
48
49
50
51
import uasyncio as asyncio
class Foo():
def __init__(self,ID):
self.ID=ID
print(f'constructor: {self.ID}')
async def sender(self):
while True:
print(f"send: {self.ID}")
await asyncio.sleep(1)
async def receiver(self):
while True:
print(f"receive: {self.ID}")
await asyncio.sleep(1)
def toto(self):
print('toto')
def run(self):
asyncio.create_task(self.sender())
asyncio.create_task(self.receiver())
async def run_forever():
while True:
await asyncio.sleep(1)
def set_global_exception():
def handle_exception(loop, context):
import sys
sys.print_exception(context["exception"])
sys.exit()
loop = asyncio.get_event_loop()
loop.set_exception_handler(handle_exception)
async def bar():
set_global_exception()
foo1 = Foo(1) # Foo is an awaitable class
foo1.run()
foo2 = Foo(2) # Foo is an awaitable class
foo2.run()
await run_forever()
if __name__=="__main__":
try:
asyncio.run(bar())
finally:
asyncio.new_event_loop()