question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug when passing a function as parameter in a delayed function

See original GitHub issue

The following script was working on 0.10.0:

from joblib import Parallel, delayed

def twice(a):
    return 2 * a

def run(method, a):
    return method(a)

if __name__ == '__main__':
    methods = [twice, ]

    results = Parallel(n_jobs=2)(delayed(run)(
        method=method, a=10) for method in methods)

Now it returns :

Traceback (most recent call last):
  File "/cal/homes/tdupre/work/src/joblib/joblib/externals/loky/process_executor.py", line 338, in _process_worker
    call_item = call_queue.get(block=True, timeout=timeout)
  File "/cal/homes/tdupre/miniconda3/envs/py36/lib/python3.6/multiprocessing/queues.py", line 113, in get
    return _ForkingPickler.loads(res)
AttributeError: Can't get attribute 'twice' on <module 'joblib.externals.loky.backend.popen_loky_posix' from '/cal/homes/tdupre/work/src/joblib/joblib/externals/loky/backend/popen_loky_posix.py'>
Traceback (most recent call last):
  File "test.py", line 17, in <module>
    method=method, a=10) for method in methods)
  File "/cal/homes/tdupre/work/src/joblib/joblib/parallel.py", line 814, in __call__
    self.retrieve()
  File "/cal/homes/tdupre/work/src/joblib/joblib/parallel.py", line 716, in retrieve
    self._output.extend(job.get(timeout=self.timeout))
  File "/cal/homes/tdupre/work/src/joblib/joblib/_parallel_backends.py", line 402, in wrap_future_result
    return future.result(timeout=timeout)
  File "/cal/homes/tdupre/work/src/joblib/joblib/externals/loky/_base.py", line 431, in result
    return self.__get_result()
  File "/cal/homes/tdupre/work/src/joblib/joblib/externals/loky/_base.py", line 382, in __get_result
    raise self._exception
joblib.externals.loky.process_executor.BrokenExecutor: A process in the process pool was terminated abruptly while the future was running or pending.

A git bisect leads to #516

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
ogriselcommented, Jul 13, 2018

I would rather like to deprecate the multiprocessing backend in the long term.

1reaction
stefdoerrcommented, Jul 6, 2018

Minimal example (sorry for the stupid names). Seems to break when passing lists of functions or class objects to a function. Works fine with single objects.

from joblib import Parallel, delayed

class MetricBad:
    def __init__(self):
        self.x = 5

    def project(self):
        self.x = 9
        return self.x

def _process(projectionlist):
    for p in projectionlist:
        res = p.project()
    return res

def _process2(projection):
    return projection.project()

results = Parallel(n_jobs=4)(delayed(_process)([MetricBad(), MetricBad()]) for i in range(20))  # Breaks
results = Parallel(n_jobs=4)(delayed(_process2)(MetricBad()) for i in range(20))  # Works

def _process3(funcs):
    for fn in funcs:
        res = fn()
    return res

def return6():
    return 6

def _process4(fn):
    return fn()

results = Parallel(n_jobs=4)(delayed(_process3)([return6, return6]) for i in range(20)) # Breaks also with lists of functions
results = Parallel(n_jobs=4)(delayed(_process4)(return6) for i in range(20)) # Works
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass a delayed function as argument to another ...
I'm writting a function that receives 3 arguments. The first argument is a function/process to be applied to each element of an array, ......
Read more >
Delay Function Help - Scripting Support - DevForum
I want to run a delay function that also brings some parameters with it. Delay function returns error “delay function requires 2 arguments”...
Read more >
Passing parameters to __delay function!
Hi, I have got a strange issue with the built-in delay function . If i type: int i=10; __delay_ms(i); I get a fail...
Read more >
Dask Delayed - Dask documentation
The Dask delayed function decorates your functions so that they operate lazily. Rather than executing your function immediately, it will defer execution, ...
Read more >
Function.prototype.bind() - JavaScript - MDN Web Docs - Mozilla
The bound function will store the parameters passed — which include ... the function, using the original object, neatly solves this problem:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found