roryk / ipython-cluster-helper

Tool to easily start up an IPython cluster on different schedulers.
148 stars 23 forks source link

Access Global Variables in function? #47

Closed GarrettBeatty closed 7 years ago

GarrettBeatty commented 7 years ago

If I have the following code for example:

a = some object

def func(x):
   return a.function(x)

x = [1,2,3]
with cluster_view(scheduler=None, queue=None, num_jobs=5,
                  extra_params={"run_local": True}) as view:
         y = view.map(func, x)

Is there a way to be able to access the "a" object? Right now I am getting the "NameError: name "a" not defined" error.

GarrettBeatty commented 7 years ago

I found the solution. I had to add direct=True as a parameter to cluster_view. Then had to add view.push({'a': a})