List Info

Thread: Re: Catching CTRL-C from the console window




Re: Catching CTRL-C from the console window
country flaguser name
United States
2007-06-26 15:19:47
--- "Drew, Matt" <Matt.Drewarraybiopharma.com> wrote:

> I have a wx.App that's running in MainLoop().  The
> user hits
> CTRL-C/CTRL-BREAK in the console window (on
> Windows).  I want to catch
> that event and run some cleanup code before exiting.
>  Nothing I can find
> will allow me to know that CTRL-C happened so I can
> run my cleanup - the
> python proces just ends immediately.
> 
> I've tried using the atexit() function, and fiddling
> with
> signal.signal(signal.SIGBREAK,
> signal.default_int_handler), both of
> which work quite nicely outside of wx-enabled python
> apps.  Sadly,
> neither works for apps in wx-land.
> 
> So, anyone got any ideas?

Solution 1:

try:
  App.MainLoop()
except KeyboardInterrupt:
  App.CleanUp()

Solution 2:

Don't use a console window, so they can't hit ^C in
it.

Gre7g


     
____________________________________________________________
________________________
Fussy? Opinionated? Impossible to please? Perfect.  Join
Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.a
sp?a=7 


------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org


Re: Catching CTRL-C from the console window
country flaguser name
United States
2007-06-26 19:23:25
Gre7g Luterman wrote:

> Solution 2:
> 
> Don't use a console window, so they can't hit ^C in
> it.

That's my vote.  Handling signals in the console window from
the GUI app 
has always been problematic, and success varies widely
across platforms.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java
give you jitters?  Relax with wxPython!


------------------------------------------------------------
---------
To unsubscribe, e-mail: wxPython-users-unsubscribelists.wxwidgets.org
For additional commands, e-mail: wxPython-users-helplists.wxwidgets.org


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )