Skip to content

Commit 7af0f08

Browse files
author
Dorian Birraux
committed
update utils asyncio
Add `run`. Remove un-used code.
1 parent 5e171a2 commit 7af0f08

2 files changed

Lines changed: 7 additions & 21 deletions

File tree

wolframclient/utils/api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
create_task="wolframclient.utils.asyncio.create_task",
8484
ensure_future="asyncio.ensure_future",
8585
wrap_future="asyncio.wrap_future",
86+
run="wolframclient.utils.asyncio.run",
8687
get_event_loop="asyncio.get_event_loop",
8788
new_event_loop="asyncio.new_event_loop",
8889
Queue="asyncio.Queue",

wolframclient/utils/asyncio.py

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ def wrapped(*args, **kwargs):
1414
return wrapped
1515

1616

17-
def run_all(args, **opts):
18-
done = tuple(iterate(*args))
19-
if done and len(done) > 1:
20-
return asyncio.ensure_future(asyncio.wait(done), **opts)
21-
elif done:
22-
return asyncio.ensure_future(first(done), **opts)
23-
return done
24-
25-
2617
def get_event_loop(loop=None):
2718
try:
2819
return loop or asyncio.get_event_loop()
@@ -32,18 +23,12 @@ def get_event_loop(loop=None):
3223
return loop
3324

3425

35-
def silence(*exceptions):
36-
def wrap(fn):
37-
@functools.wraps(fn)
38-
def wrapper(*args, **kwargs):
39-
try:
40-
return fn(*args, **kwargs)
41-
except tuple(exceptions):
42-
pass
43-
44-
return wrapper
45-
46-
return wrap
26+
if hasattr(asyncio, 'run'):
27+
run = asyncio.run
28+
else:
29+
def run(main):
30+
loop = get_event_loop()
31+
return loop.run_until_complete(main)
4732

4833

4934
if hasattr(asyncio, "create_task"):

0 commit comments

Comments
 (0)