The following is posted verbatim from @dtkerrs review of #49 with regard to the switchy.distribute.MultiEval interface and implementation:
So some feedback here on evals is that it might be nicer to not use string-based commands in the various calls. If your evals call used the __code__ attribute, if it exists, on the expression you could rewrite something like
def is_alive(self):
return any(self.pool.evals('listener.is_alive()'))
as
def is_alive(self):
def alive():
listener.is_alive()
return any(self.pool.evals(alive))
which I think is nicer personally.
I haven't looked at all of it, but if the only goal of evals is to let you call methods or get attributes from the listener or client it might also make more sense to rewrite evals to let you call it something like either of these:
def is_alive(self):
return any(self.pool.evals(lambda listener: listener.is_alive()))
def is_alive(self):
def slave_alive(listener):
return listener.is_alive()
return any(self.pool.evals(slave_alive))
Which can work since you can extract the name of arguments from a code object by looking at co_varnames
@vodik also commented:
I think I'd agree with @dtkerr suggestion because I can't see how eval could be faster than a function call. Evaluating code should have more overhead, no?
Looking at your code, I see how and why you do the evals - to run the same snippet with different globals/locals, but I don't see how any of that is desirable over function calls...
The following is posted verbatim from @dtkerrs review of #49 with regard to the
switchy.distribute.MultiEvalinterface and implementation:@vodik also commented: