-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathasyncio_debug.py
More file actions
47 lines (35 loc) · 931 Bytes
/
asyncio_debug.py
File metadata and controls
47 lines (35 loc) · 931 Bytes
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
import argparse
import asyncio
import logging
import sys
import time
import warnings
parser = argparse.ArgumentParser("debugging asyncio")
parser.add_argument(
"-v",
dest="verbose",
default=False,
action="store_true",
)
args = parser.parse_args()
logging.basicConfig(
level=logging.DEBUG,
format="%(levelname)7s: %(message)s",
stream=sys.stderr,
)
LOG = logging.getLogger("")
async def inner():
LOG.info("inner starting")
time.sleep(0.1)
LOG.info("inner complete")
async def outer(loop):
LOG.info("outer starting")
await asyncio.ensure_future(loop.create_task(inner()))
LOG.info("outer completed")
event_loop = asyncio.get_event_loop()
if args.verbose:
LOG.info("enabling debugging")
event_loop.set_debug(True)
event_loop.slow_callback_duration = 0.001
warnings.simplefilter("always", ResourceWarning)
event_loop.run_until_complete(outer(event_loop))