A way to wait Python event

C

Chang LI

I tried to launch "python.exe test.py" in another program. After the
launch the console was showed and exited on Windows. I want the
console stay there. Is there a Python statement to wait an event loop
like Tcl's "after forever"?
 
D

Diez B. Roggisch

I tried to launch "python.exe test.py" in another program. After the
launch the console was showed and exited on Windows. I want the
console stay there. Is there a Python statement to wait an event loop
like Tcl's "after forever"?

I'm a happy linux user who is always amazed by such things when using
windows. So the first thing I do on a windows-box is to install cygwin, and
then execute commands from a proper shell.

Apart from that, I believe what you expirience has nothing to do with python
- windows just kills the command-window if your app exits. And thats well
after python is actually in command.

So maybe you can do somthing like this:

if __name__ == "__main__":
try:
... # do something
except:
print sys.exc_info()[1]
while True:
time.sleep(0.2)

That should stop the interpreter in case of an exception. Unindenting the
last while will wait in every case, so you can inspect the output
nonetheless.

Apart from that, there might be some hidden "keep this damn window open
after the executed progam terminated"-checkbox. Happy hunting.
 
M

Marcello Pietrobon

Chang said:
I tried to launch "python.exe test.py" in another program. After the
launch the console was showed and exited on Windows. I want the
console stay there. Is there a Python statement to wait an event loop
like Tcl's "after forever"?
If you need to keep a cmd window open maybe you can try this.
Unfortunately I don't have time to screen which lines are exactly the
ones you need.

I don't remember why it is like that.
For example I guess you can remove it the line realated to notepad

You'll figure out the best way to use it. But I suggest you to first
look at the preexisting values of those keys.
So you can come back to the preexisting situation if you don't like it (
you'll see


Take the following lines and put them in .reg file. Then run it.
After that when you right click on a file you'll have the option to open
it with Notepad or with a Command prompt that stays open.

Hope it helps.


Cheers,
Marcello


--------------------------------------------
REGEDIT4

[HKEY_CLASSES_ROOT\*]

[HKEY_CLASSES_ROOT\*\shell]

[HKEY_CLASSES_ROOT\*\shell\dos_box]
@="DOS Box"

[HKEY_CLASSES_ROOT\*\shell\dos_box\command]
@="cmd"

[HKEY_CLASSES_ROOT\*\shell\open]
@="Notepad"

[HKEY_CLASSES_ROOT\*\shell\open\command]
@="Notepad.exe %1"

[HKEY_CLASSES_ROOT\Folder\shell]

[HKEY_CLASSES_ROOT\Folder\shell\dos_box]
@="DOS Box"

[HKEY_CLASSES_ROOT\Folder\shell\dos_box\command]
@="cmd /k cd %1"

[HKEY_CLASSES_ROOT\batfile\shell]

[HKEY_CLASSES_ROOT\batfile\shell\runstayopen]
@="R&un - Stay open"

[HKEY_CLASSES_ROOT\batfile\shell\runstayopen\command]
@="cmd /k %1"

[HKEY_CLASSES_ROOT\comfile\shell]

[HKEY_CLASSES_ROOT\comfile\shell\runstayopen]
@="R&un - Stay open"

[HKEY_CLASSES_ROOT\comfile\shell\runstayopen\command]
@="cmd /k %1"

[HKEY_CLASSES_ROOT\exefile\shell]

[HKEY_CLASSES_ROOT\exefile\shell\runstayopen]
@="R&un - Stay open"

[HKEY_CLASSES_ROOT\exefile\shell\runstayopen\command]
@="cmd /k %1"

---------------------------
 
J

Josiah Carlson

I tried to launch "python.exe test.py" in another program. After the
launch the console was showed and exited on Windows. I want the
console stay there. Is there a Python statement to wait an event loop
like Tcl's "after forever"?

I'm a fan of...

_ = raw_input('press enter to continue...')


- Josiah
 
Joined
Dec 30, 2009
Messages
5
Reaction score
0
Or you just do

import os
os.system("pause")

It´s work well!!

Regards Schawm RS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top