我想做什么:
我成功地做了什么:
问题:
"PyAssertionError: C++ assertion "wxThread::IsMain()" failed at ..\..\src\common\timercmn.cpp(66)
in wxTimerBase::Start(): timer can only be started from the main thread "
编码:
def start_socket(self):
HOST = ''
PORT_A = 6340
self.server_A = ThreadedTCPServer((HOST, PORT_A), ThreadedTCPRequestHandler)
self.server_temp = self.server_A
self.server_A_thread = threading.Thread(target=self.server_A.serve_forever)
self.server_A_thread.setDaemon(True)
self.server_A_thread.start()
class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
self.Main = Main(None, -1, '')
self.data = self.request.recv(1024).strip()
print "%s wrote: " % self.client_address[0]
print self.data
plt.ion()
self.fig = plt.figure(1)
print self.image_scale
ax = self.fig.add_subplot(111)
self.image_scale = ([1,2], [ 4,10 ] )
cax = plt.imshow(self.image_scale, cmap='Greys', interpolation='nearest' )
draw()
通过调试,错误来自这一行:
self.fig = plt.figure(1)
Error: "timer can only be started from the main thread"
所以,不确定,但我想我需要在wx.Frame的main函数中进行绘图,是否有任何解决方案可以保持正常程序运行,并允许在另一个线程中实时绘图?特别是我打算制作多个 TCPServer 线程。
在此先感谢您,您的帮助将不胜感激。
最佳答案
无论如何,谢谢,我解决了它,现在从不同的线程运行计时器,
它在语言上的限制,有解决方法它可以工作
关于python - wxPython 多线程 matplotlib 绘图不在主线程中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14585230/