Skip to content

Commit 0ec33ad

Browse files
committed
fixes #808
1 parent 2901fe7 commit 0ec33ad

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

fastcore/script.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'set_ctx', 'call_parse']
88

99
# %% ../nbs/06_script.ipynb #8a36db98
10-
import inspect,argparse,shutil,types
10+
import inspect,argparse,shutil,types,asyncio
1111

1212
from functools import wraps,partial
1313
from .imports import *
@@ -167,7 +167,8 @@ def _f(*args, **kwargs):
167167
args = args.__dict__
168168
xtra = otherwise(args.pop('xtra', ''), eq(1), p.prog)
169169
tfunc = trace(func) if args.pop('pdb', False) else func
170-
return tfunc(**merge(args, args_from_prog(func, xtra)))
170+
res = tfunc(**merge(args, args_from_prog(func, xtra)))
171+
return asyncio.run(res) if inspect.isawaitable(res) else res
171172

172173
mod = inspect.getmodule(inspect.currentframe().f_back)
173174
if getattr(mod, '__name__', '') =="__main__":

nbs/06_script.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
"outputs": [],
179179
"source": [
180180
"#| export\n",
181-
"import inspect,argparse,shutil,types\n",
181+
"import inspect,argparse,shutil,types,asyncio\n",
182182
"\n",
183183
"from functools import wraps,partial\n",
184184
"from fastcore.imports import *\n",
@@ -804,7 +804,8 @@
804804
" args = args.__dict__\n",
805805
" xtra = otherwise(args.pop('xtra', ''), eq(1), p.prog)\n",
806806
" tfunc = trace(func) if args.pop('pdb', False) else func\n",
807-
" return tfunc(**merge(args, args_from_prog(func, xtra)))\n",
807+
" res = tfunc(**merge(args, args_from_prog(func, xtra)))\n",
808+
" return asyncio.run(res) if inspect.isawaitable(res) else res\n",
808809
"\n",
809810
" mod = inspect.getmodule(inspect.currentframe().f_back)\n",
810811
" if getattr(mod, '__name__', '') ==\"__main__\":\n",

0 commit comments

Comments
 (0)