Sending data (BytesIO buffer) through a Pipe works but causes a Fatal Python exception

给你一囗甜甜゛ 提交于 2019-12-11 14:49:01

问题


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()

Here is the error:

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

回答1:


Adding a short sleep command seems to do the trick...

conn.send(plt.imread(buf))
time.sleep(.001)
conn.close

Not elegant but works.



来源:https://stackoverflow.com/questions/47023141/sending-data-bytesio-buffer-through-a-pipe-works-but-causes-a-fatal-python-exc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!