0

Suppose I have two Python files

test.py

from ipyparallel import Client

def hi(a):
    return b + (a * 2)

def run():
    b = 3

    client = Client()
    view = client[:]

    view.push({'b':b})
    results = view.map(hi, [0,1,2,3,4])
    for r in results:
        print(r)

and driver.py

from test import run

if __name__ == '__main__':
    run()

I get the error [0:apply]: NameError: name 'b' is not defined.

This code will work if I call run() from within test.py, however, I do not want to do that. I want to call run() from within driver.py. Any ideas on how to fix this?

1

1 Answer 1

0

In test.py file import interactive, then, in map function use interactive(hi) instead of hi:

from ipyparallel import Client
from ipyparallel.util import interactive

def hi(a):
    global b
    return b + (a * 2)

def run():
    b = 3
    client = Client()
    view = client[:]
    view.push({'b':b})
    results = view.map(interactive(hi), [0,1,2,3,4])
    for r in results:
        print(r)

if __name__ == '__main__':
    run()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.