pgiri / dispy

Distributed and Parallel Computing Framework with / for Python
https://dispy.org
Other
266 stars 55 forks source link

Method inside method, is there a better way? #205

Closed kaanaksit closed 4 years ago

kaanaksit commented 4 years ago

I am a happy user of dispy. First of all, thank you for making it happen!

Context

Assume there are three files that represents my python program:

Inside routine.py, I import compute from simulation.py and start a cluster accordingly.

Sturggle

I need some more methods/definitions/functions from simulation.py during compute, and my solution was to embed these other things into the compute as in below example:

def compute():
      def other_function_1():
            return 5
      def other_function_2():
           return 10
      result =  other_function_1()+other_function_2()
      return result

I find my solution to be very ugly.If I leave the other_functions outside of compute, I always get this can not find module error even if I try importing simulate.py inside compute.

Is there a better way to do this? Your help and suggestion is very much appreciated!

pgiri commented 4 years ago

One possibility (easier approach?) is to put functions in a module (separate file), send it with depends and have compute function import that module and use functions in that module.

kaanaksit commented 4 years ago

Thank you. That resolved my case. I followed your suggestion and

pgiri commented 4 years ago

Great! Note that there is no need to import new module in client program (where cluster is generated), unless functions in new module are used in processing results etc.