今天封楼被困公司,研究了一下 ProcessPoolExecutor,发现了一个 Python 的 Bug,分享...
source link: https://www.v2ex.com/t/849250
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
今天封楼被困公司,研究了一下 ProcessPoolExecutor,发现了一个 Python 的 Bug,分享给各位,网上似乎没解决方案
v2exblog · 22 小时 56 分钟前 · 1396 次点击用的 python3.7.13 。报错信息如下兄弟们:
很奇怪为什么不能 raise key-value 格式的自定义错误 ,
要是改成 raise MyError( 1, 'desc') 就没问题了,这是不是 python 的 bug?
# 这是代码,直接,可以运行
from concurrent.futures.process import ProcessPoolExecutor
class MyError(Exception):
def __init__(self, code: int, desc: str):
self.code = code
self.desc = desc
def foo(i, j):
print(i, j)
raise MyError(code=1, desc='desc')
def main():
with ProcessPoolExecutor(3) as executor:
f = executor.submit(foo, 1, 11)
e = f.exception()
print(e)
f.result()
if __name__ == '__main__':
main()
下面是输出结果:
1 11
A process in the process pool was terminated abruptly while the future was running or pending.
concurrent.futures.process._RemoteTraceback:
'''
Traceback (most recent call last):
File "/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/process.py", line 367, in _queue_management_worker
result_item = result_reader.recv()
File "/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/connection.py", line 251, in recv
return _ForkingPickler.loads(buf.getbuffer())
TypeError: __init__() missing 2 required positional arguments: 'code' and 'desc'
'''
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/v2exblog/demo/aaa.py", line 25, in <module>
main()
File "/Users/v2exblog/demo/aaa.py", line 21, in main
f.result()
File "/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 428, in result
return self.__get_result()
File "/Python.framework/Versions/3.7/lib/python3.7/concurrent/futures/_base.py", line 384, in __get_result
raise self._exception
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending.
Recommend
-
66
被困10米高架桥2年1月31日,四川成都市阳光明媚。青羊区三环路附近一处高架桥,约10米高的桥墩一座挨一座,缠绕在桥墩上的爬山虎已经枯萎,只留下枯枝随风摇摆。在其中一个桥墩的缝隙中,一只小猫已经被困2年了。这期间有人想搭梯子去救它,但因太高
-
39
-
39
最近,泰国一名足球教练与12个孩子被困洞穴、历经9天终于被找到的消息相信不少人都有所耳闻。可能几乎所有人听说找到之后就放心了,但事实上,一个星期过去了,这些孩子依然没能救出来!目前,除了泰国派出的至少1000名救援人员,中国、英国、美国、澳大利亚、缅甸...
-
50
全部获救!被困洞穴18天,泰国12名足球少年和教练终获安全!【环球网报道 记者 孙广勇 查希...
-
35
-
39
12月1日凌晨开始,新疆克拉玛依12级狂风肆虐,黄沙漫天,视距最差时不足2米。有货车司机被困,发出求救信息,接警后救援官兵动用重型装甲车等装备搜救,成功解救被困人员。
-
4
深圳赛格大厦因未知原因晃动封楼 WinterIsComing (31822)发表于 2021年05月21日 1...
-
5
Python高级(7)—进程池ProcessPoolExecutor、线程池ThreadPoolExecutor◎知识点◎脚本练习▽进程池ProcessPoolExecutor""" 标准库模块conc...
-
3
← 世界首例:医生对子宫内的胎儿实施脑部手术Diehard @ 2023.05.09 , 17:31...
-
3
V2EX › 职场话题 今天儿童节,细数一下前公司的各种骚操作,给大家带来点欢乐
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK