当我打开一个文本文件时wxPython应用程序挂起/崩溃
问题描述:
好吧,我有一个用wxPython编写的应用程序。有一个按钮被绑定到一个函数,该函数的一部分需要应用程序在kate中打开一个文本文件。当我打开一个文本文件时wxPython应用程序挂起/崩溃
因此,该文件在gedit中打开并且工作正常,但是当您查看该应用程序时,您可以看到该按钮仍然被推入并且似乎冻结。几秒钟后,应用程序将变灰并挂起/崩溃。如果我关闭编辑窗口,它会解冻并重新开始工作。
为什么当我打开文本文件时,我的应用程序挂起?我使用这段代码写入文本文件,然后在kate中打开它。
file = open("encryptedText.txt", "w")
file.write(encryptedStr)
file.close()
os.system("kate encryptedText.txt")
谢谢!
对不起,缩进不是问题。我搞砸了后格式。下面是我得到了终端上的消息:
'import sitecustomize' failed; use -v for traceback
QDBusConnection: session D-Bus connection created before QCoreApplication. Application may misbehave.
kate(13256)/kate-filetree KateFileTreePluginView::KateFileTreePluginView: BEGIN: mw: Kate::MainWindow(0xeab140)
kate(13256)/kate-filetree ProxyItem::ProxyItem: ProxyItem(0x1219ad0,0x0,-1,QObject(0x0) ,"m_root")
kate(13256)/kate-filetree ProxyItem::ProxyItem: ProxyItem(0x1219db0,0x0,-1,QObject(0x0) ,"Untitled")
kate(13256)/kate-filetree KateFileTreeModel::documentOpened: before add: ProxyItem(0x1219db0,0x0,-1,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeModel::setupIcon: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::setupIcon: END!
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: empty item
kate(13256)/kate-filetree ProxyItem::addChild: added ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled") to ProxyItemDir(0x1219ad0,0x0,-1,"m_root", children:1)
kate(13256)/kate-filetree KateFileTreeModel::documentOpened: after add: ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeProxyModel::KateFileTreeProxyModel: BEGIN!
kate(13256)/kate-filetree KateFileTreePluginView::setListMode: BEGIN
kate(13256)/kate-filetree KateFileTreePluginView::setListMode: treeMode
kate(13256)/kate-filetree KateFileTreePluginView::setListMode: END
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: BEGIN!
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: BEGIN!
kate(13256)/kate-filetree KateFileTreeProxyModel::docIndex: !
kate(13256)/kate-filetree KateFileTreeModel::docIndex: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::docIndex: END!
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: selected doc= KateDocument(0x103da90) QModelIndex(0,0,0x1214690,KateFileTreeProxyModel(0x126b040))
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: display= "Untitled"
kate(13256)/kate-filetree KateFileTreeModel::documentActivated: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::documentActivated: adding viewHistory ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeModel::updateBackgrounds: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::updateBackgrounds: END!
kate(13256)/kate-filetree KateFileTreeModel::documentActivated: END!
kate(13256)/kate-filetree KateFileTree::slotCurrentChanged: current: QModelIndex(0,0,0x1214690,KateFileTreeProxyModel(0x126b040)) previous: QModelIndex(-1,-1,0x0,QObject(0x0))
kate(13256)/kate-filetree KateFileTree::slotCurrentChanged: got doc, setting prev: QModelIndex(0,0,0x1214690,KateFileTreeProxyModel(0x126b040))
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: END!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: change to unnamed item
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: "Untitled" -> "Untitled"
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: removing brush ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: removing view history ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: bogus name change
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: END!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "Untitled")
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: "Untitled" -> "/home/harvey/Documents/Python Development/encryptedText.txt"
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: removing ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt") from ProxyItemDir(0x1219ad0,0x0,-1,"m_root", children:1)
kate(13256)/kate-filetree KateFileTree::slotCurrentChanged: current: QModelIndex(-1,-1,0x0,QObject(0x0)) previous: QModelIndex(0,0,0x1214690,KateFileTreeProxyModel(0x126b040))
kate(13256)/kate-filetree ProxyItem::remChild: remove ProxyItem(0x1219db0,0x1219ad0,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt") from ProxyItemDir(0x1219ad0,0x0,-1,"m_root", children:1)
kate(13256)/kate-filetree KateFileTreeModel::handleEmptyParents: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::handleEmptyParents: parent ProxyItemDir(0x1219ad0,0x0,-1,"m_root", children:0) grandparentProxyItemDir(0x0)
kate(13256)/kate-filetree KateFileTreeModel::setupIcon: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::setupIcon: END!
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: inserting ProxyItem(0x1219db0,0x0,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt")
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: creating a new root
kate(13256)/kate-filetree ProxyItem::ProxyItem: ProxyItem(0x14d5460,0x0,-1,QObject(0x0) ,"/home/harvey/Documents/Python Development")
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: add ProxyItemDir(0x14d5460,0x0,-1,"/home/harvey/Documents/Python Development", children:0) to m_root
kate(13256)/kate-filetree ProxyItem::addChild: added ProxyItem(0x14d5460,0x1219ad0,0,QObject(0x0) ,"/home/harvey/Documents/Python Development") toProxyItemDir(0x1219ad0,0x0,-1,"m_root", children:1)
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: attempting to merge some existing roots
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: adding ProxyItem(0x1219db0,0x0,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt") to ProxyItemDir(0x14d5460,0x1219ad0,0,"/home/harvey/Documents/Python Development", children:0)
kate(13256)/kate-filetree ProxyItem::addChild: added ProxyItem(0x1219db0,0x14d5460,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt") to ProxyItemDir(0x14d5460,0x1219ad0,0,"/home/harvey/Documents/Python Development", children:1)
kate(13256)/kate-filetree KateFileTreeModel::handleInsert: END!
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: END!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: END!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: ProxyItem(0x1219db0,0x14d5460,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt")
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: "encryptedText.txt" -> "/home/harvey/Documents/Python Development/encryptedText.txt"
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::handleNameChange: bogus name change
kate(13256)/kate-filetree KateFileTreeModel::documentNameChanged: END!
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: BEGIN!
kate(13256)/kate-filetree KateFileTreeProxyModel::docIndex: !
kate(13256)/kate-filetree KateFileTreeModel::docIndex: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::docIndex: END!
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: selected doc= KateDocument(0x103da90) QModelIndex(0,0,0x1572820,KateFileTreeProxyModel(0x126b040))
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: display= "encryptedText.txt"
kate(13256)/kate-filetree KateFileTreeModel::documentActivated: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::documentActivated: adding viewHistory ProxyItem(0x1219db0,0x14d5460,0,KateDocument(0x103da90) , "/home/harvey/Documents/Python Development/encryptedText.txt")
kate(13256)/kate-filetree KateFileTreeModel::updateBackgrounds: BEGIN!
kate(13256)/kate-filetree KateFileTreeModel::updateBackgrounds: END!
kate(13256)/kate-filetree KateFileTreeModel::documentActivated: END!
kate(13256)/kate-filetree KateFileTree::slotCurrentChanged: current: QModelIndex(0,0,0x1572820,KateFileTreeProxyModel(0x126b040)) previous: QModelIndex(-1,-1,0x0,QObject(0x0))
kate(13256)/kate-filetree KateFileTree::slotCurrentChanged: got doc, setting prev: QModelIndex(0,0,0x1572820,KateFileTreeProxyModel(0x126b040))
kate(13256)/kate-filetree KateFileTreePluginView::viewChanged: END!
答
很可能与线程的问题:你的脚本等待kate
回调,并得到不高兴什么不会发生(但有时kate
确实是......)
一个潜在的解决方法是让kate
在后台做她的事情。您应该使用
os.system('kate yourfile &')
与&
在后台中的含义。或者,您也可以使用subprocess
模块。你会做这样的事情:
subprocess.Popen(["kate", "yourfile"])
(你也可以查看this SO post)
是否有终端上的任何错误输出? – vinnydiehl
修复您的缩进 – lolopop
线程问题?你的GUI等着凯特完成?你有没有试过用'os.system(kate ...&')'在后台打开它? –