python怎么强制结束进程_Python多进程的子进程终止问题

我需要在python中使用多进程,可是我发现不论是multiprocessing.pool.Pool还是concurrent.futures.ProcessPoolExecutor都没有提供对子进程的终止?我现在急需要这样的功能,该如何实现?

我有看ProcessPoolExecutor的源代码,ProcessPoolExecutor大概就是在submit后会把参数视为一个work_item,添加到call_queue中去,再由_process_worker取出call_item并运行,感觉也没法用hack的手段来实现终止啊。。

下面是ProcessPoolExecutor中的部分核心源代码。。

def _process_worker(call_queue, result_queue):

"""Evaluates calls from call_queue and places the results in result_queue.

This worker is run in a separate process.

Args:

call_queue: A multiprocessing.Queue of _CallItems that will be read and

evaluated by the worker.

result_queue: A multiprocessing.Queue of _ResultItems that will written

to by the worker.

shutdown: A multiprocessing.Event that will be set as a signal to the

worker that it should exit when call_queue is empty.

"""

while True:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值