Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to add some work before worker shutdown or restart #81

Closed
CyberQin opened this issue Apr 14, 2021 · 2 comments
Closed

how to add some work before worker shutdown or restart #81

CyberQin opened this issue Apr 14, 2021 · 2 comments

Comments

@CyberQin
Copy link

any way to do some extra work before worker shutdown or restart?

@CyberQin
Copy link
Author

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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants