好的,所以我有一个用wxPython编写的应用程序。有一个绑定到函数的按钮,该函数的一部分需要应用程序在kate中打开一个文本文件。
因此,文件在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!
答案 0 :(得分:1)
os.system
在进程终止时返回,例如,当您关闭kate时,因此在完成编辑之前函数不会结束。
使用subprocess.Popen
和this作为替代。
答案 1 :(得分:1)
这可能是线程的一个问题:你的脚本等待kate
回调,而且不会发生什么事情(但kate
有时会这样做...)
一个潜在的解决方法是让kate
在后台做她的事情。你应该使用
os.system('kate yourfile &')
背景中&
含义。或者,您可能希望使用subprocess
模块。你可以这样做:
subprocess.Popen(["kate", "yourfile"])
(你也可以查看this SO post)