Feature Requests item #739624, was opened at 2003-05-19 10:38
Message generated for change (Comment added) made by mhammond
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551957&aid=739624&group_id=78018
Category: None
Group: None
Status: Open
Priority: 5
Submitted By: Mark Hammond (mhammond)
Assigned to: Nobody/Anonymous (nobody)
Summary: Implement SetConsoleCtrlHandler
Initial Comment:
Includes a patch and discussion.
----------------------------------------------------------------------
>Comment By: Mark Hammond (mhammond)
Date: 2003-05-19 10:39
Message:
Logged In: YES
user_id=14198
we talked about SetConsoleCtrlHandler a while ago.
>Sorry for the delay, but yes, that sounds like a reasonable
> approach. The only problem is with the "last-registered,
> first-called" approach, meaning second calls to your
> extensions function would not have the same effect as a
> second call to the real SetConsoleCtrlHandler - but yeah,
> I see no reasonable solution worth the effort.
>
>The GIL management will not be trivial, and may require
> you to get - err - creative :)
The GIL wasn't too hard in the end - the handler is called
in the context
of a new thread, and there is precedent for that in the
source :)
I have attached a simplistic version of a
SetConsoleCtrlHandler. It allows
to set *one* handler function and doesn't implement the list
I originally
had in mind.
The code works works, but its behaviour is far from the
behaviour of
SetConsoleCtrlHandler in a C program.
This is probably due to the signal handling of Python
itself, and I can't
see what can be done about it.
The current code is useful to me, and it could be improved
to handle
multiple handlers properly (by installing different C
handlers, thereby
preserving the order), but it would be rather hard to
document the
behaviour, since it clashes with the Python internal signal
handling.
For example, take:
import cch # this is the console controle handler module
import time
def handler(type):
print type
return False
cch.SetConsoleCtrlHandler(handler, True)
time.sleep(60)
If you execute this, and hit Ctrl-C before the 60 seconds
are up, the
handler will dutifully print 0, but the process won't be
killed - because
time.sleep() cannot be killed in Python.
If you do a sys.exit() in the handler function, it will also
not terminate
the process, since sys.exit() only works from the main thread.
Basically, I have no clue how the Python
SetConsoleCtrlHandler should be
documented. It would need a link to description of standard
Python signal
handling to be generally useful, but I am not aware of any
such documentation.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551957&aid=739624&group_id=78018
|