Skip to content

Commit 0a1832e

Browse files
author
Michele Simionato
committed
Using asyncio.run
1 parent a4c9663 commit 0a1832e

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/tests/documentation.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ def factorial(n, acc=1):
855855
```python
856856
import time
857857
import logging
858-
from asyncio import get_event_loop, sleep, wait
858+
from asyncio import run, sleep, wait
859859
from decorator import decorator
860860
861861
@decorator
@@ -874,7 +874,7 @@ async def make_task(n):
874874
if __name__ == '__main__':
875875
logging.basicConfig(level=logging.INFO)
876876
tasks = [make_task(3), make_task(2), make_task(1)]
877-
get_event_loop().run_until_complete(wait(tasks))
877+
run(wait(tasks))
878878
```
879879
880880
and you will get an output like this:
@@ -903,7 +903,7 @@ async def make_task(n):
903903
@decorator
904904
def coro_to_func(coro, *args, **kw):
905905
"Convert a coroutine into a function"
906-
return get_event_loop().run_until_complete(coro(*args, **kw))
906+
return run(coro(*args, **kw))
907907
```
908908
909909
Notice the difference: the caller in ``log_start_stop`` was a coroutine

src/tests/test.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import decimal
55
import inspect
66
import functools
7-
from asyncio import get_event_loop
7+
import asyncio
88
from collections import defaultdict, ChainMap, abc as c
99
from decorator import dispatch_on, contextmanager, decorator
1010
try:
@@ -31,7 +31,7 @@ async def before_after(coro, *args, **kwargs):
3131

3232
@decorator
3333
def coro_to_func(coro, *args, **kw):
34-
return get_event_loop().run_until_complete(coro(*args, **kw))
34+
return asyncio.run(coro(*args, **kw))
3535

3636

3737
class CoroutineTestCase(unittest.TestCase):
@@ -40,7 +40,7 @@ def test_before_after(self):
4040
async def coro(x):
4141
return x
4242
self.assertTrue(inspect.iscoroutinefunction(coro))
43-
out = get_event_loop().run_until_complete(coro('x'))
43+
out = asyncio.run(coro('x'))
4444
self.assertEqual(out, '<before>x<after>')
4545

4646
def test_coro_to_func(self):

0 commit comments

Comments
 (0)