Skip to main content
  1. About
  2. For Teams
Asked
Viewed 82 times
0

I have the following script:

from multiprocessing import Lock, Pool

def worker():
    r = other.work()
    return r

def main():
    pool = Pool(4)
    result = pool.apply_sync(worker,())
    result.wait()

In worker(), I call function work() from another module 'other', However, I forget to import the module 'other'. But when I ran this python script, python didn't report any Exception. Is this a bug ?

2
  • Your code snippet contains an error on line 9 with that comma inside the empty-set: result = pool.apply_sync(worker,(,))
    Paul Rigor
    –  Paul Rigor
    2014-04-29 23:57:45 +00:00
    Commented Apr 29, 2014 at 23:57
  • Its possible that the async call is supressing the output of an exception. To test this you could write a function that raises an exception and see what happens. The other possibility is that there is some class other already within the namespace that python calls instead.
    aplassard
    –  aplassard
    2014-04-30 00:11:25 +00:00
    Commented Apr 30, 2014 at 0:11

1 Answer 1

2

Any errors that are raised in the spawned processes will remain silent until you actually retrieve the result.

from multiprocessing import Lock, Pool

def worker():
    r = other.work()
    return r

def main():
    pool = Pool(4)

    # note: this is apply_async, not apply_sync
    result = pool.apply_async(worker,())
    result.wait()

    # See here
    actual_result = result.get()

This will raise:

NameError: global name 'other' is not defined

What you have named result is a multiprocessing.pool.ApplyResult object which is more like the promise of a return value, than a return value itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.