This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Python 2.7. Script interruption on logoff from 0 session under Win2003 and earlier
Type: behavior Stage:
Components: Extension Modules, Windows Versions: Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: iritkatriel, steve.dower, tim.golden, vScherba, zach.ware
Priority: normal Keywords: patch

Created on 2014-02-04 19:03 by vScherba, last changed 2022-04-11 14:57 by admin.

Files
File name Uploaded Description Edit
ConsoleCtrlHandler.patch vScherba, 2014-02-04 19:21 review
Messages (5)
msg210259 - (view) Author: Victor Scherba (vScherba) Date: 2014-02-04 19:03
To get the bug:
1. Windows Server 2003 (same bug should be under earlier versions: XP, 2000, ...).
2. Any Windows service should spawn process with Python script.
3. Py script should stay into time.sleep.
4. Any Windows user should login in console session 0.
5. Bug: when this user logoff, script interrupts.

To repeat the bug simply you could use srvany which spawn: python.exe -c "import time; time.sleep(10000)".

There is problem in cpython/Modules/timemodule.c in PyCtrlHandler.
Before logoff Windows broadcasts to all services and its children CTRL_LOGOFF_EVENT signal. But PyCtrlHandler doesn't filter it out by dwCtrlType and always sets hInterruptEvent. This forces script interruption.

CTRL_SHUTDOWN_EVENT also should be filtered out. CTRL_SHUTDOWN_EVENT broacasted to all services before Windows shutdown. But after it has been handled, other process can block or pause shutdowning.

Default Windows console control handler does not call ExitProcess when processing the CTRL_LOGOFF_EVENT and CTRL_SHUTDOWN_EVENT signals. See more at http://msdn.microsoft.com/en-us/library/windows/desktop/ms683242(v=vs.85).aspx

On Win Vista and higher bug not presents. Impossible to login to session 0 because of session 0 isolation.

Patch attached. There is same fix in cpython/Modules/_multiprocessing/multiprocessing.c
msg222581 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-07-08 19:55
Looking at PEP 11 and this http://support.microsoft.com/lifecycle/?c2=1163 it seems to depend on which service pack you've got as to whether or not Win2003 is supported by 2.7.  Can one of our Windows gurus take a look please, it's as clear as mud to me.
msg222582 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2014-07-08 20:45
Windows Server 2003, XP, and 2000 are all officially supported by Python 2.7, as they were all current (for certain values of "current") at the time Python 2.7 was released.

That said, it's not completely clear to me what the bug is but it strikes me as being something that's not all that likely to be hit, and either way about it, I don't have any way to test it.
msg222596 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2014-07-09 01:59
Looks like a legitimate issue to me, and the patch is fine. It's probably something that ought to be fixed in default too, since I don't see how it is restricted to session 0 - any Python service will incorrectly treat these notifications as interruptions.

Sent from my Windows Phone
________________________________
From: Zachary Ware<mailto:report@bugs.python.org>
Sent: ‎7/‎8/‎2014 15:45
To: Steve Dower<mailto:Steve.Dower@microsoft.com>
Subject: [issue20513] Python 2.7. Script interruption on logoff from 0 session under Win2003 and earlier

Zachary Ware added the comment:

Windows Server 2003, XP, and 2000 are all officially supported by Python 2.7, as they were all current (for certain values of "current") at the time Python 2.7 was released.

That said, it's not completely clear to me what the bug is but it strikes me as being something that's not all that likely to be hit, and either way about it, I don't have any way to test it.

----------

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue20513>
_______________________________________
msg396089 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-18 21:09
The patch doesn't look anything like the current code. Is this issue still relevant?
History
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64712
2021-06-18 21:09:50iritkatrielsetnosy: + iritkatriel
messages: + msg396089
2019-04-26 18:33:53BreamoreBoysetnosy: - BreamoreBoy
2014-07-09 01:59:50steve.dowersetmessages: + msg222596
title: Python 2.7. Script interruption on logoff from 0 session under Win2003 and earlier -> Python 2.7. Script interruption on logoff from 0 session under Win2003 and earlier
2014-07-08 20:45:45zach.waresetmessages: + msg222582
2014-07-08 19:55:52BreamoreBoysetnosy: + BreamoreBoy, tim.golden, zach.ware, steve.dower
messages: + msg222581
2014-02-04 19:28:18vScherbasettitle: Script interruption on logoff from 0 session under Win2003 and earlier -> Python 2.7. Script interruption on logoff from 0 session under Win2003 and earlier
2014-02-04 19:22:51vScherbasetfiles: + ConsoleCtrlHandler.patch
2014-02-04 19:22:31vScherbasetfiles: - ConsoleCtrlHandler.patch
2014-02-04 19:21:08vScherbasetfiles: + ConsoleCtrlHandler.patch
keywords: + patch
2014-02-04 19:03:28vScherbacreate