Comments (6)
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.
Original comment by: mhammond
from pywin32.
from lars
Original comment by: mhammond
from pywin32.
from lars
Original comment by: mhammond
from pywin32.
from lars
Original comment by: mhammond
from pywin32.
SetConsoleCtrlHandler was added to win32api module on 10.10.2004. Can this feature request be closed?
Original comment by: zseil
from pywin32.
- status: open --> closed-fixed
Original comment by: mhammond
from pywin32.
Related Issues (20)
- Does it support winUI3 HOT 1
- Scripting with win32api fails in Python 3.12 HOT 10
- Exposing RealGetWindowClass
- 'win32ui' has no attribute 'CreatePrinterDC' HOT 1
- When will a new version be released? HOT 3
- where the fuck is win32crypt HOT 5
- Client missing? HOT 1
- __import_pywin32_system_module_ function is not finding pywintypesXX.dll even if it exists HOT 1
- Last error code errorneously set by some modules
- Free-threaded support? HOT 3
- Missing support for record pointers as method parameters of a Dispatch Interface.
- Support for MFC's dynamic layout in win32ui
- Unable to install directly from Git via pip HOT 1
- Can't find pywintypes in virtual environment HOT 2
- how to set line spacing for shape / tables in pptx?
- BUG: EnsureDispatch always executes the code to build makepy support even if it already exists.
- Error on hosting a FastAPI Application with Windows Service
- `glob.glob1` is deprecated in Python3.13, undocumented and not meant to be public
- Using pydoc on start_pythonwin causes executable code to run
- WM_LBUTTONDOWN not triggered until WM_LBUTTONUP HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pywin32.