how to add some work before worker shutdown or restart
CyberQin opened this issue · 2 comments
CyberQin commented
any way to do some extra work before worker shutdown or restart?
CyberQin commented
import multiprocessing as mp
from multiprocessing import Process
from itertools import cycle
ix=[1,2]
cy=cycle(ix)
ctx=mp.get_context()
class MyProc(ctx.Process):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
print(f"my name:{self.name}")
# def terminate(self):
# print(f"my name:{self.name}")
def join(self):
super().join()
print(f"my name:{self.name}")
# def close(self):
# print(f"my name:{self.name}")
ctx.Process=MyProc
import rx
import concurrent.futures as cf
import rx.operators as ops
def bb(f):
return f
if __name__ == '__main__':
with cf.ProcessPoolExecutor(max_workers=3,mp_context=ctx) as excutor:
cd=rx.from_iterable([1,2,3,4,5,6,7,8]).pipe(
ops.map(lambda x:excutor.submit(bb,x))
)
cd.subscribe()
dd=cd.__await__()
maybe can try this
noxdafox commented
Please do not use GitHub for questions. This is a place where to report bugs and request features and not to get HowTos.
The right place for that, is stackoverflow
.