本文介绍了通过管道发送数据(BytesIO缓冲区)有效,但会导致致命的Python异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Windows上使用Python 2.7,以下代码可以运行,但会导致msvc问题.
Using Python 2.7 on Windows, the following code works but causes a problem with msvc.
import io
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt2
from multiprocessing import Process, Pipe
def tmpPlot(conn):
plt.plot([1,2,4,2])
plt.title("title")
buf = io.BytesIO()
plt.savefig(buf, format='png')
buf.seek(0)
conn.send(plt.imread(buf))
conn.close
if __name__ == '__main__':
parent_conn, child_conn = Pipe()
p = Process(target=tmpPlot, args=(child_conn,))
p.start()
imgData = parent_conn.recv()
imgplt = plt2.imshow(imgData)
plt2.show()
这是错误:
随后pythonw.exe已停止工作消息:
Followed by pythonw.exe has stopped working message:
Problem signature:
Problem Event Name: APPCRASH
Application Name: pythonw.exe
Application Version: 0.0.0.0
Application Timestamp: 59bd8782
Fault Module Name: python27.dll
Fault Module Version: 2.7.14150.1013
Fault Module Timestamp: 59bd877e
Exception Code: 40000015
Exception Offset: 0014098b
OS Version: 6.0.6002.2.2.0.768.3
Locale ID: 1033
Additional Information 1: ac4a
Additional Information 2: 817fddeef0c50f6183a834229ec12634
Additional Information 3: 3df9
Additional Information 4: 47d9390827b4b422b52d14c0c48ab5d9
Read our privacy statement:
http://go.microsoft.com/fwlink/?linkid=50163&clcid=0x0409
推荐答案
添加短睡眠命令似乎可以解决问题……
Adding a short sleep command seems to do the trick...
conn.send(plt.imread(buf))
time.sleep(.001)
conn.close
不优雅,但是可以用.
这篇关于通过管道发送数据(BytesIO缓冲区)有效,但会导致致命的Python异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!