Python 3:生成进程子类

cha*_*ker 2 python python-3.x python-multiprocessing

multiprocessing我们可以使用已创建的上下文使用Python 3 创建非分叉进程:

ctx = multiprocessing.get_context('spawn')
p = ctx.Process(target=foo, args=(42,))
p.start()
Run Code Online (Sandbox Code Playgroud)

但假设我正在使用Process. 有没有办法Process使用除 之外的方法创建子类实例fork

Dan*_*iel 6

继承自ctx.Process

ctx = multiprocessing.get_context('spawn')
class CustomProcess(ctx.Process):
    # define methods
Run Code Online (Sandbox Code Playgroud)