[Tutor] time.sleep problem

Tim Peters tim.one@comcast.net
Mon, 08 Jul 2002 23:28:31 -0400


[BELSEY, Dylan]
> ...
> 	While doing the sleep I tried CTRL-C and you are right, it doesn't
> react immediately. When trying it another time, it waits till the code
> finishes and then returns me to the DOS prompt.  Perhaps it is an
> issue with the processor or thread being caught/held in the sleep call
> and  being unable to respond to the shutdown signal immediately.

time.sleep() on Windows is implemented by calling Microsoft's Sleep()
function (part of the Win32 API).  The Win32 Sleep() can't be interrupted.
Here are some comments from the floatsleep() function in Python's
timemodule.c:

#if defined(HAVE_SELECT) && !defined(__BEOS__) && !defined(__EMX__)
...
#ifdef EINTR
...
#else
...
#endif
#elif defined(macintosh)
#define MacTicks	(* (long *)0x16A)
...
		/* XXX Should call some yielding function here */
...
#elif defined(__WATCOMC__) && !defined(__QNX__)
	/* XXX Can't interrupt this sleep */
...
#elif defined(MS_WINDOWS)
...
		/* XXX Can't interrupt this sleep */
...
#elif defined(PYOS_OS2)
	/* This Sleep *IS* Interruptable by Exceptions */
...
#elif defined(__BEOS__)
	/* This sleep *CAN BE* interrupted. */
...
#elif defined(RISCOS)
...
	/* This sleep *CAN BE* interrupted. */
...
#elif defined(PLAN9)
...
		/* This sleep *CAN BE* interrupted. */
...
#else
	/* XXX Can't interrupt this sleep */
...
#endif

You're in the MS_WINDOWS part of this miserable maze; just be thankful
you're on the outside looking in <wink>.