-1

Okay so I've got an application written in wxPython. There's a button which is bound to a function and part of that function requires the application to open a text file in kate.

So, the file opens in gedit and works fine, but when you look at the application, you can see the button is still pushed in and seems frozen. After a few seconds the application will grey out and hang/crash. If I close the edit window, it'll unfreeze and start working again.

Why is it that when I open a text file, my app hangs? I'm using this code to write to the textfile and then open it in kate.

file = open("encryptedText.txt", "w")
file.write(encryptedStr)
file.close()
os.system("kate encryptedText.txt")

Thanks!


Sorry, the indentation isn't an issue. I messed up the post formatting. Here's the message I'm getting on the terminal:

'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!
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
user1675111
  • 8,695
  • 4
  • 18
  • 14
  • 1
    Is there any error output on the terminal? – vinnydiehl Sep 25 '12 at 13:42
  • 1
    A threading problem? Your GUI waits for Kate to finish? Have you tried to open it in the background with `os.system(kate ... &`)` ? – Pierre GM Sep 25 '12 at 13:48
  • Sorry. It isn't the indentation, I formatted the post incorrectly. This is the message I'm getting on the terminal... – user1675111 Sep 25 '12 at 13:49
  • I think it might be a threading issue. It definitely looks like the GUI is waiting for kate to finish. I've never used threading before, I'm still new to Python. How would I go about opening it in the background? – user1675111 Sep 25 '12 at 13:52
  • 1
    @user1675111: I just gave you the answer! Use a `&` at the end of your command in `os.system` – Pierre GM Sep 25 '12 at 13:54

2 Answers2

1

os.system returns when the process is terminated, e.g., when you close kate, therefore function doesn't end until you finish editing.

Use subprocess.Popen and this as a replacement.

Community
  • 1
  • 1
unddoch
  • 5,790
  • 1
  • 24
  • 37
1

It's likely an issue with threads: your script waits for kate to call back, and it gets upset what that doesn't happen (but kate does that sometimes...)

A potential fix is to let kate do her thing in the background. You should use

os.system('kate yourfile &')

with the & meaning in the background. Alternatively, you may want to use the subprocess module instead. You would do something like:

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

(And you could also check this SO post)

Community
  • 1
  • 1
Pierre GM
  • 19,809
  • 3
  • 56
  • 67