From 756b93de990b995d511801560ca8f9913cbc80a2 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 21 Dec 2017 08:36:15 +0200 Subject: [PATCH 1/5] Dont unsubscribe signals in UNIX even loop on interpreter shutdown --- Lib/asyncio/unix_events.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 69c719c3239005..15ce3bf0e304aa 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -51,8 +51,12 @@ def __init__(self, selector=None): def close(self): super().close() - for sig in list(self._signal_handlers): - self.remove_signal_handler(sig) + if not sys.is_finalizing(): + for sig in list(self._signal_handlers): + self.remove_signal_handler(sig) + else: + warinigs.warn(f"Closing the loop {self} on interpreter shutdown " + f"stage, signal unsubsription is disabled") def _process_self_data(self, data): for signum in data: From b2b4a7eae01a788a75d09460a0eefbb9cfd9ffce Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 21 Dec 2017 09:16:23 +0200 Subject: [PATCH 2/5] Add stacklevel 2 for raised message --- Lib/asyncio/unix_events.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 15ce3bf0e304aa..86500b1ae0ee83 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -56,7 +56,8 @@ def close(self): self.remove_signal_handler(sig) else: warinigs.warn(f"Closing the loop {self} on interpreter shutdown " - f"stage, signal unsubsription is disabled") + f"stage, signal unsubsription is disabled", + stacklevel=2) def _process_self_data(self, data): for signum in data: From 0a0b8c966925083fdc76f328562e99d0d2ec760f Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 21 Dec 2017 11:08:54 +0200 Subject: [PATCH 3/5] Add NEWS entry --- .../NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst diff --git a/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst b/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst new file mode 100644 index 00000000000000..92033da82e8b82 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst @@ -0,0 +1 @@ +Dont unsubscribe signals in asyncio UNIX event loop on interpreter shutdown. From 41a9f22b71439e074f5f42e97f44cd2de5a99a04 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 21 Dec 2017 13:35:36 +0200 Subject: [PATCH 4/5] Fix notes --- Lib/asyncio/unix_events.py | 4 ++-- .../next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 86500b1ae0ee83..1dc14d186f48a2 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -55,9 +55,9 @@ def close(self): for sig in list(self._signal_handlers): self.remove_signal_handler(sig) else: - warinigs.warn(f"Closing the loop {self} on interpreter shutdown " + warinigs.warn(f"Closing the loop {self!r} on interpreter shutdown " f"stage, signal unsubsription is disabled", - stacklevel=2) + ResourceWarning) def _process_self_data(self, data): for signum in data: diff --git a/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst b/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst index 92033da82e8b82..0653d1960e5697 100644 --- a/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst +++ b/Misc/NEWS.d/next/Library/2017-12-21-11-08-42.bpo-26133.mt81QV.rst @@ -1 +1 @@ -Dont unsubscribe signals in asyncio UNIX event loop on interpreter shutdown. +Don't unsubscribe signals in asyncio UNIX event loop on interpreter shutdown. From 628d68eb5648766ea8502e12fb4748e1b9c3cd63 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Thu, 21 Dec 2017 13:58:38 +0200 Subject: [PATCH 5/5] Add source-self --- Lib/asyncio/unix_events.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py index 1dc14d186f48a2..ec767f57d3aa0f 100644 --- a/Lib/asyncio/unix_events.py +++ b/Lib/asyncio/unix_events.py @@ -57,7 +57,8 @@ def close(self): else: warinigs.warn(f"Closing the loop {self!r} on interpreter shutdown " f"stage, signal unsubsription is disabled", - ResourceWarning) + ResourceWarning, + source=self) def _process_self_data(self, data): for signum in data: