You should use callbacks
A callbacks
is a function that you pass to the submit
call. That function will be called with the result of the job as argument (have a look at the API for more arcane usage).
In your case
Set up a callback:
class TestClass:
def doSomething(self):
j = 2 * self.i
return j # It's REQUIRED that you return j here.
def set_j(self, j):
self.j = j
Add the callback to the job submit call
class parallellClass:
def __init__(self):
#your code...
job_list.append(job_server.submit(TC.doSomething, callback=TC.set_j))
And you're done.
I made some improvements to the code to avoid using self.j
in the doSomething
call, and only use a local j
variable.
As mentioned in the comments, in pp
, you only communicate the result of your job. That's why you have to return this variable, it will be passed to the callback.