-1

好的,所以我有一个用 wxPython 编写的应用程序。有一个按钮绑定到一个函数,该函数的一部分需要应用程序在 kate.xml 中打开一个文本文件。

因此,该文件在 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!
4

2 回答 2

1

os.system当进程终止时返回,例如,当您关闭 kate 时,因此函数在您完成编辑之前不会结束。

使用subprocess.Popen这个作为替代品。

于 2012-09-25T14:02:16.433 回答
1

这可能是线程的问题:您的脚本等待kate回调,并且它会因为没有发生而感到不安(但kate有时会这样做......)

一个潜在的解决办法是让kate她在后台做事。你应该使用

os.system('kate yourfile &')

&背景中的含义。或者,您可能希望改用该subprocess模块。你会做这样的事情:

subprocess.Popen(["kate", "yourfile"])

(你也可以查看这个 SO 帖子

于 2012-09-25T14:02:53.347 回答