0

在 Windows 上使用 Python 2.7,以下代码可以工作,但会导致 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()

这是错误:

MSVC 错误

随后是 pythonw.exe 已停止工作的消息:

  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
4

1 回答 1

0

添加一个简短的睡眠命令似乎可以解决问题......

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

不优雅但有效。

于 2017-11-01T00:44:33.910 回答