A way to wait Python event

Discussion in 'Python' started by Chang LI, Nov 30, 2004.

  1. Chang LI

    Chang LI Guest

    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"?
     
    Chang LI, Nov 30, 2004
    #1
    1. Advertising

  2. > 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.
    --
    Regards,

    Diez B. Roggisch
     
    Diez B. Roggisch, Nov 30, 2004
    #2
    1. Advertising

  3. Chang LI wrote:

    >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"

    ---------------------------
     
    Marcello Pietrobon, Nov 30, 2004
    #3
  4. (Chang LI) wrote:
    >
    > 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
     
    Josiah Carlson, Dec 3, 2004
    #4
  5. Chang LI

    Schawm

    Joined:
    Dec 30, 2009
    Messages:
    5
    Or you just do

    import os
    os.system("pause")

    It´s work well!!

    Regards Schawm RS
     
    Schawm, Jan 5, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Craig Deelsnyder

    Re: best way to do a "please wait" message

    Craig Deelsnyder, Aug 3, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    814
  2. Huey

    How to make "fork/wait" to WAIT longer?

    Huey, Mar 1, 2004, in forum: C Programming
    Replies:
    1
    Views:
    2,010
    -berlin.de
    Mar 1, 2004
  3. Alex007

    Portable way to wait for a keypress

    Alex007, Jun 15, 2004, in forum: C Programming
    Replies:
    7
    Views:
    8,849
    Kenneth Brody
    Jun 15, 2004
  4. RajW
    Replies:
    9
    Views:
    327
  5. kevinliu23

    Best way to wait for string input

    kevinliu23, Mar 29, 2007, in forum: Python
    Replies:
    1
    Views:
    289
    Marc 'BlackJack' Rintsch
    Mar 29, 2007
Loading...

Share This Page