You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Callables passed into TaskGraph.add_task currently have to be named functions defined in the global scope. There are many cases where it would be convenient to pass in a lambda function defined in-line. I'm specifically thinking about raster_map, e.g.
It would be convenient to write op=lambda x: ..., but that breaks when n_workers > 0 because the args must be pickled. And pickle cannot pickle lambdas or local objects.
Taskgraph could support lambdas and local callables by using multiprocess, a fork of python's multiprocessing that supports pickling more types. I briefly tried replacing multiprocessing with multiprocess in Task.py and it worked (test suite passed and was able to pass lambdas into taskgraph). But there could be other implications of using multiprocess, like conflicts with multiprocessing if both were used.
It's also worth noting that, while python supports pickling functools.partials, taskgraph raises an error because it relies on the __name__ attribute. It would be nice to support partials too.
Traceback (most recent call last):
File "/Users/emily/miniconda3/envs/main/lib/python3.10/site-packages/taskgraph/Task.py", line 625, in add_task
new_task = Task(
File "/Users/emily/miniconda3/envs/main/lib/python3.10/site-packages/taskgraph/Task.py", line 1003, in __init__
scrubbed_value = _scrub_task_args(arg, self._target_path_list)
File "/Users/emily/miniconda3/envs/main/lib/python3.10/site-packages/taskgraph/Task.py", line 1459, in _scrub_task_args
return '%s:%s' % (base_value.__name__, source_code)
AttributeError: 'functools.partial' object has no attribute '__name__'. Did you mean: '__ne__'?
The text was updated successfully, but these errors were encountered:
We talked about this today and decided to wait until after the taskgraph 1.0 release. Taskgraph has been stable for a while now, and we want to do the release before mixing anything up.
There might be more minimal ways to add support for lambdas, like patching multiprocessing without using multiprocess, or passing in lambdas as strings.
Callables passed into
TaskGraph.add_task
currently have to be named functions defined in the global scope. There are many cases where it would be convenient to pass in a lambda function defined in-line. I'm specifically thinking aboutraster_map
, e.g.It would be convenient to write
op=lambda x: ...
, but that breaks whenn_workers > 0
because the args must be pickled. Andpickle
cannot pickle lambdas or local objects.Taskgraph could support lambdas and local callables by using
multiprocess
, a fork of python'smultiprocessing
that supports pickling more types. I briefly tried replacingmultiprocessing
withmultiprocess
in Task.py and it worked (test suite passed and was able to pass lambdas into taskgraph). But there could be other implications of usingmultiprocess
, like conflicts withmultiprocessing
if both were used.It's also worth noting that, while python supports pickling
functools.partial
s, taskgraph raises an error because it relies on the__name__
attribute. It would be nice to supportpartial
s too.The text was updated successfully, but these errors were encountered: