- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在开发一个使用 Twisted 和 wxReactor 的程序。每次我尝试退出应用程序时,它都会挂起,我必须强制退出它。我的 wxPython OnClose() 事件确实调用了reactor.stop(),据我所知,这应该可以解决这个问题。在寻求答案的过程中,我发现了这张票:www.twistedmatrix.com/trac/ticket/3948。
我已经尝试过页面上列出的补丁,但没有成功。我已经解决这个问题两周了,我非常绝望:)。
给大家一些关于这个项目的背景知识:它是一个免费软件客户端,使用套接字连接到多人游戏服务器(目前玩 Monopoly 和 Uno)。如果运行它,您会立即注意到没有图形。这是因为该客户端仅通过语音合成和音效提供音频反馈。该项目的目标受众是视障游戏玩家。
要测试该问题,请运行 python rsg.py(可以在 src 文件夹中找到。如果您需要知道,我使用 Python 2.6.5)。在终端中,您将看到程序产生的输出(主要是服务器发送到客户端的输出)。一旦看到“Connection Made”行(运行后不久就会打印出来),请尝试关闭程序(通过单击 X)。客户端将挂起几秒钟,然后您需要强制退出应用程序(在 Ubuntu 上,它会询问我是否要强制退出应用程序)。
我确实知道为什么它不能正常退出。当我通过 gdb 运行它时,两个线程没有退出。奇怪的是,如果服务器关闭连接,然后我退出程序,它就会正常工作。
我真的很感谢所有的帮助。预先感谢您。
编辑 由于我被要求提供我的问题的基本演示,所以它是:
import wx
import sys
from twisted.internet import wxreactor
wxreactor.install()
# import t.i.reactor only after installing wxreactor:
from twisted.internet import reactor
from twisted.protocols.basic import LineReceiver
from twisted.internet.protocol import ClientFactory
class ZGPClient(LineReceiver):
"""Our client object."""
def lineReceived(self, datavar):
"As soon as any data is received"
print datavar
class EchoFactory(ClientFactory):
protocol = ZGPClient
def startedConnecting(self, connector):
global conn
conn = connector
print 'Started to connect.'
def sendData(self, data=""):
conn.transport.write(data.encode("ascii", "ignore") + "\n")
class main_window(wx.Frame):
def __init__(self, parent, id, title):
super(main_window, self).__init__(parent, id, title, style=wx.DEFAULT_FRAME_STYLE)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Show(True)
def OnClose(self, event):
reactor.stop()
sys.exit()
if __name__ == "__main__":
app = wx.App()
frame = main_window(None, wx.ID_ANY, "RS Games Client - No Game")
reactor.registerWxApp(app)
sockObj = EchoFactory()
reactor.connectTCP("rsgamesmonserver.webhop.org", 3555, sockObj)
reactor.run()
app.MainLoop()
最佳答案
这对你有用:
def OnClose(self, evt):
# ugly hack until wxreactor is patched:
reactor._stopping = True
reactor.callFromThread(_threadedselect.ThreadedSelectReactor.stop, reactor)
关于python - wxReactor问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4190120/
我是一名优秀的程序员,十分优秀!