Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Control-C alternative in Windows

Reply
Thread Tools

Control-C alternative in Windows

 
 
Vlad Dogaru
Guest
Posts: n/a
 
      12-17-2006
Hello,

I've written a simple, standalone wiki server in Python. It runs a
BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is
caught, at which point it writes changes to a file and exits. This
works as expected in Linux. However, in Windows I cannot stop the
script with Control-C. I've only been able to stop it with Ctrl-Break,
which does not send KeyboardInterrupt. This means no saving to the file
and effectively a useless script. Any ideas as to how I might make this
work in Windows?

Thanks in advance,
Vlad

 
Reply With Quote
 
 
 
 
Kleine Aap
Guest
Posts: n/a
 
      12-17-2006
Vlad Dogaru wrote:

> I've written a simple, standalone wiki server in Python. It runs a
> BaseHTTPServer's serve_forever() method until a KeyboardInterrupt is
> caught, at which point it writes changes to a file and exits. This
> works as expected in Linux. However, in Windows I cannot stop the
> script with Control-C. I've only been able to stop it with Ctrl-Break,
> which does not send KeyboardInterrupt. This means no saving to the file
> and effectively a useless script. Any ideas as to how I might make this
> work in Windows?


(http://www.python.org/download/relea...2.2/NEWS.txt):

The signal module now supports SIGBREAK on Windows, thanks to Steven
Scott. Note that SIGBREAK is unique to Windows. The default SIGBREAK
action remains to call Win32 ExitProcess(). This can be changed via
signal.signal(). For example:

# Make Ctrl+Break raise KeyboardInterrupt, like Python's default Ctrl+C
# (SIGINT) behavior.
import signal
signal.signal(signal.SIGBREAK,
signal.default_int_handler)

try:
while 1:
pass
except KeyboardInterrupt:
# We get here on Ctrl+C or Ctrl+Break now; if we had not changed
# SIGBREAK, only on Ctrl+C (and Ctrl+Break would terminate the
# program without the possibility for any Python-level cleanup).
print "Clean exit"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Quicktime Alternative, RealPlayer Alternative & Media Player Classic John Capleton Computer Support 3 12-05-2005 07:41 AM
An Alternative to Installing an MMC Snap-In in Windows 2000 Professional bluelizardman@gmail.com Computer Support 0 03-02-2005 10:27 AM
need alternative windows update site dakine Computer Support 9 10-16-2004 02:43 AM
BeOS - alternative to Windows *** JB Computer Support 3 04-07-2004 09:49 AM
Alternative to Windows' Scandisk? grobda Computer Support 23 01-12-2004 02:29 AM



Advertisments