Stupid Windows Question

Gordon McMillan gmcm at hypernet.com
Thu May 27 11:15:38 EDT 1999


Mark Nottingham writes:

> What's the equivalent of an alarm() on Windows? I need to time out a
> httplib fetch of a URL...

Hee hee. I love signals on WIndows.

The following signals are defined (MSVC docs):
--------------------------------------
SIGABRT
 Abnormal termination

SIGFPE
 Floating-point error

SIGILL
 Illegal instruction

SIGINT
 CTRL+C signal

SIGSEGV
 Illegal storage access

SIGTERM
 Termination request
--------------------------------------------
but you'll never get a SIGINT, because WIndows spawns a new thread to 
handle it. However:
----------------------------------------
The SIGILL, SIGSEGV, and SIGTERM signals are not generated under
Windows NT. They are included for ANSI compatibility [editor's note: 
har de har har har]. Thus you can set signal handlers for these 
signals with signal, and you can also explicitly generate these 
signals by calling raise.
----------------------------------------

So, on NT at least (who knows about the others) you could emulate 
SIGALRM with a windows timer and a raise(). Snort.

More straightforward would be to use select with a timeout on the 
socket, but that's more hackery of a different sort... Or use 
threads, and just kiss off the thread if it doesn't respond within 
your timeout.

- Gordon




More information about the Python-list mailing list