Crash when passing named function as an argument
See original GitHub issueHello,
I am using Python 3.6.5
with joblib 0.11.1.dev0
(master).
Consider the two files:
# test_imp.py
def foo_imp(i):
return i+2
# test.py
from joblib import Parallel, delayed
def foo(i):
return i+1
def wrap(i, func):
return func(i)
# runs fine
from test_imp import foo_imp
res = Parallel(n_jobs=2)([delayed(wrap)(i, foo_imp) for i in range(10)])
print(res)
# crashes
res = Parallel(n_jobs=2)([delayed(wrap)(i, foo) for i in range(10)])
print(res)
When passing an imported function foo_imp
as an argument, the code runs fine. For the locally defined function foo
however, I get the following error:
Traceback (most recent call last):
File "/python/site-packages/joblib/externals/loky/process_executor.py", line 376, in _process_worker
call_item = call_queue.get(block=True, timeout=timeout)
File "/python3.6/multiprocessing/queues.py", line 113, in get
return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'foo' on <module 'joblib.externals.loky.backend.popen_loky_posix' from '/python/site-packages/joblib/externals/loky/backend/popen_loky_posix.py'>
Is this intended behavior? It might be related to #600.
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Passing pointer to function changes data and crashes program
On the end of createWeapon() , the wp variable, local variable of createWeapon() , is destroyed. Therefore, the returned pointer points to " ......
Read more >JavaScript: Why Named Arguments are Better than Positional ...
This pattern of passing objects to functions is called named arguments. It is lot more explicit than positional arguments. To change the radix ......
Read more >Why is my FormatMessage call crashing trying to read my ...
The bug is that code is reusing the ap parameter without resetting it. The documentation for FormatMessage says about the Arguments parameter:.
Read more >Name=Value in Function Calls - MATLAB & Simulink
MATLAB ® supports two syntaxes for passing name-value arguments. ... Use the name=value syntax to help identify name-value arguments for functions and to...
Read more >Functions - TypeScript: Handbook
We can add types to each of the parameters and then to the function itself to ... The compiler will build an array...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I have pushed a fix for this issue in master. It should be faster too when issuing many short tasks.
You could introspect the object using a function like
Be careful that you need to go a bit further to ensure that the unpickling is done properly. You could for instance wrap the objects from main in a class such as
Edit: Sorry I ended-up creating the pull request. Feel free to test it and report if you see bad behaviors.