@@ -112,11 +112,11 @@ def PathArg(
112
112
path : str # A filesystem path
113
113
): return Path (path )
114
114
115
- # %% ../01_funccall.ipynb 65
115
+ # %% ../01_funccall.ipynb 66
116
116
import ast , time , signal , traceback
117
117
from fastcore .utils import *
118
118
119
- # %% ../01_funccall.ipynb 66
119
+ # %% ../01_funccall.ipynb 67
120
120
def _copy_loc (new , orig ):
121
121
"Copy location information from original node to new node and all children."
122
122
new = ast .copy_location (new , orig )
@@ -125,7 +125,7 @@ def _copy_loc(new, orig):
125
125
elif isinstance (o , list ): setattr (new , field , [_copy_loc (value , orig ) for value in o ])
126
126
return new
127
127
128
- # %% ../01_funccall.ipynb 68
128
+ # %% ../01_funccall.ipynb 69
129
129
def _run (code :str ):
130
130
"Run `code`, returning final expression (similar to IPython)"
131
131
tree = ast .parse (code )
@@ -148,7 +148,7 @@ def _run(code:str ):
148
148
if _result is not None : return _result
149
149
return stdout_buffer .getvalue ().strip ()
150
150
151
- # %% ../01_funccall.ipynb 73
151
+ # %% ../01_funccall.ipynb 74
152
152
def python (code , # Code to execute
153
153
timeout = 5 # Maximum run time in seconds before a `TimeoutError` is raised
154
154
): # Result of last node, if it's an expression, or `None` otherwise
@@ -161,7 +161,7 @@ def handler(*args): raise TimeoutError()
161
161
except Exception as e : return traceback .format_exc ()
162
162
finally : signal .alarm (0 )
163
163
164
- # %% ../01_funccall.ipynb 80
164
+ # %% ../01_funccall.ipynb 81
165
165
def mk_ns (* funcs_or_objs ):
166
166
merged = {}
167
167
for o in funcs_or_objs :
@@ -170,7 +170,7 @@ def mk_ns(*funcs_or_objs):
170
170
if callable (o ) and hasattr (o , '__name__' ): merged |= {o .__name__ : o }
171
171
return merged
172
172
173
- # %% ../01_funccall.ipynb 89
173
+ # %% ../01_funccall.ipynb 90
174
174
def call_func (fc_name , fc_inputs , ns ):
175
175
"Call the function `fc_name` with the given `fc_inputs` using namespace `ns`."
176
176
if not isinstance (ns , abc .Mapping ): ns = mk_ns (* ns )
0 commit comments