Python多进程 struct.error: ‘i‘ format
生活随笔
收集整理的這篇文章主要介紹了
Python多进程 struct.error: ‘i‘ format
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
當對多個文件進行同樣的預處理時,為了加快處理速度會使用Python多進程。每個進程返回數據給父進程,做最后的合并處理。
問題描述與分析
代碼在處理大文件時候會拋出如下錯誤,但當處理的文件較小時候,一切正常。
concurrent.futures.process._RemoteTraceback: """ Traceback (most recent call last):File "/home/dxi/software/python3.7.9/lib/python3.7/concurrent/futures/process.py", line 205, in _sendback_resultexception=exception))File "/home/dxi/software/python3.7.9/lib/python3.7/multiprocessing/queues.py", line 364, in putself._writer.send_bytes(obj)File "/home/dxi/software/python3.7.9/lib/python3.7/multiprocessing/connection.py", line 200, in send_bytesself._send_bytes(m[offset:offset + size])File "/home/dxi/software/python3.7.9/lib/python3.7/multiprocessing/connection.py", line 393, in _send_bytesheader = struct.pack("!i", n) struct.error: 'i' format requires -2147483648 <= number <= 2147483647多進程時候,進程間數據交換是通過pickling,因為處理的文本都比較大,當數據pickled時候超過了i struct的限制,-2147483648 <= number <= 2147483647
Python3.8中在非windows平臺修復了這個問題,可以支持最大4EB的數據。
解決方法
基于上述分析,可以嘗試以下幾種解決方法
參考文獻
python struct.error: ‘i’ format requires -2147483648 <= number <= 2147483647
總結
以上是生活随笔為你收集整理的Python多进程 struct.error: ‘i‘ format的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 我爱许巍
- 下一篇: python format 用法详解