In general, self.model.optimize(self.mycallback)
should work (note: no parens after mycallback
).
It may fail if the code serializes the callable e.g., to be send via pipe/socket to another process (even on different machine):
from multiprocessing import Pool
class C:
def method(self, i):
return "called", i
if __name__=="__main__":
print(Pool().map(C().method, range(10)))
It works on recent Python versions where methods are pickable.
Or it may fail if model.optimize()
has a bug and check for the exact function type instead of accepting any callable.