From e22813067e4f62629a9c24947c29a55861fb05f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Fran=C3=A7ois=20Natali?= Date: Thu, 14 Jul 2011 19:53:38 +0200 Subject: Issue #12502: asyncore: fix polling loop with AF_UNIX sockets. --- Lib/asyncore.py | 6 ++++-- Misc/NEWS | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 00464a9..3f0d2d3 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -130,7 +130,8 @@ def poll(timeout=0.0, map=None): is_w = obj.writable() if is_r: r.append(fd) - if is_w: + # accepting sockets should not be writable + if is_w and not obj.accepting: w.append(fd) if is_r or is_w: e.append(fd) @@ -177,7 +178,8 @@ def poll2(timeout=0.0, map=None): flags = 0 if obj.readable(): flags |= select.POLLIN | select.POLLPRI - if obj.writable(): + # accepting sockets should not be writable + if obj.writable() and not obj.accepting: flags |= select.POLLOUT if flags: # Only check for exceptions if object was either readable diff --git a/Misc/NEWS b/Misc/NEWS index 1e98768a..63d5c24 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -22,6 +22,8 @@ What's New in Python 3.1.4? Library ------- +- Issue #12502: asyncore: fix polling loop with AF_UNIX sockets. + - Issue #12009: Fixed regression in netrc file comment handling. Extension Modules -- cgit v0.12 From 8cdc40e3b0622ea4eeb8b2c9b0e6796be685d16d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 15 Jul 2011 21:15:07 +0200 Subject: =?UTF-8?q?Issue=20#11603:=20Fix=20a=20crash=20when=20=5F=5Fstr=5F?= =?UTF-8?q?=5F=20is=20rebound=20as=20=5F=5Frepr=5F=5F.=20Patch=20by=20Andr?= =?UTF-8?q?eas=20St=C3=BChrk.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Lib/test/test_descr.py | 8 ++++++++ Misc/NEWS | 3 +++ Objects/typeobject.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index c74e232..0ce85f0 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4252,6 +4252,14 @@ order (MRO) for bases """ with self.assertRaises(TypeError): str.__add__(fake_str, "abc") + def test_repr_as_str(self): + # Issue #11603: crash or infinite loop when rebinding __str__ as + # __repr__. + class Foo: + pass + Foo.__repr__ = Foo.__str__ + foo = Foo() + str(foo) class DictProxyTests(unittest.TestCase): def setUp(self): diff --git a/Misc/NEWS b/Misc/NEWS index 63d5c24..b14e169 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,9 @@ Core and Builtins Library ------- +- Issue #11603: Fix a crash when __str__ is rebound as __repr__. Patch by + Andreas Stührk. + What's New in Python 3.1.4? =========================== diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 5c20e0d..70971f3 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2821,7 +2821,7 @@ object_str(PyObject *self) unaryfunc f; f = Py_TYPE(self)->tp_repr; - if (f == NULL) + if (f == NULL || f == object_str) f = object_repr; return f(self); } -- cgit v0.12 From c081c0c6a0c917de72b7d7944c5316174717d56d Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Fri, 15 Jul 2011 22:12:24 +0200 Subject: Issue #12573: Add resource checks for dangling Thread and Process objects. --- Lib/multiprocessing/process.py | 5 +++++ Lib/test/regrtest.py | 37 ++++++++++++++++++++++++++++++++++++- Lib/threading.py | 4 ++++ Misc/NEWS | 2 ++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py index 941893f..5987af9 100644 --- a/Lib/multiprocessing/process.py +++ b/Lib/multiprocessing/process.py @@ -42,6 +42,7 @@ import os import sys import signal import itertools +from _weakrefset import WeakSet # # @@ -105,6 +106,7 @@ class Process(object): self._kwargs = dict(kwargs) self._name = name or type(self).__name__ + '-' + \ ':'.join(str(i) for i in self._identity) + _dangling.add(self) def run(self): ''' @@ -328,3 +330,6 @@ _exitcode_to_name = {} for name, signum in list(signal.__dict__.items()): if name[:3]=='SIG' and '_' not in name: _exitcode_to_name[-signum] = name + +# For debug and leak testing +_dangling = WeakSet() diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py index 14fa005..8ca7f6c 100755 --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -172,6 +172,15 @@ import unittest import warnings from inspect import isabstract +try: + import threading +except ImportError: + threading = None +try: + import multiprocessing.process +except ImportError: + multiprocessing = None + # Some times __path__ and __file__ are not absolute (e.g. while running from # Lib/) and, if we change the CWD to run the tests in a temporary dir, some @@ -864,7 +873,8 @@ class saved_test_environment: 'os.environ', 'sys.path', 'sys.path_hooks', '__import__', 'warnings.filters', 'asyncore.socket_map', 'logging._handlers', 'logging._handlerList', - 'sys.warnoptions') + 'sys.warnoptions', 'threading._dangling', + 'multiprocessing.process._dangling') def get_sys_argv(self): return id(sys.argv), sys.argv, sys.argv[:] @@ -952,6 +962,31 @@ class saved_test_environment: sys.warnoptions = saved_options[1] sys.warnoptions[:] = saved_options[2] + # Controlling dangling references to Thread objects can make it easier + # to track reference leaks. + def get_threading__dangling(self): + if not threading: + return None + # This copies the weakrefs without making any strong reference + return threading._dangling.copy() + def restore_threading__dangling(self, saved): + if not threading: + return + threading._dangling.clear() + threading._dangling.update(saved) + + # Same for Process objects + def get_multiprocessing_process__dangling(self): + if not multiprocessing: + return None + # This copies the weakrefs without making any strong reference + return multiprocessing.process._dangling.copy() + def restore_multiprocessing_process__dangling(self, saved): + if not multiprocessing: + return + multiprocessing.process._dangling.clear() + multiprocessing.process._dangling.update(saved) + def resource_info(self): for name in self.resources: method_suffix = name.replace('.', '_') diff --git a/Lib/threading.py b/Lib/threading.py index fd93f74..d260983 100644 --- a/Lib/threading.py +++ b/Lib/threading.py @@ -6,6 +6,7 @@ import _thread from time import time as _time, sleep as _sleep from traceback import format_exc as _format_exc from collections import deque +from _weakrefset import WeakSet # Note regarding PEP 8 compliant names # This threading model was originally inspired by Java, and inherited @@ -606,6 +607,8 @@ _active_limbo_lock = _allocate_lock() _active = {} # maps thread id to Thread object _limbo = {} +# For debug and leak testing +_dangling = WeakSet() # Main class for threads @@ -640,6 +643,7 @@ class Thread(_Verbose): # sys.stderr is not stored in the class like # sys.exc_info since it can be changed between instances self._stderr = _sys.stderr + _dangling.add(self) def _reset_internal_locks(self): # private! Called by _after_fork() to reset our internal locks as diff --git a/Misc/NEWS b/Misc/NEWS index a30f132..00bce49 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -67,6 +67,8 @@ C-API Tests ----- +- Issue #12573: Add resource checks for dangling Thread and Process objects. + - Issue #12549: Correct test_platform to not fail when OS X returns 'x86_64' as the processor type on some Mac systems. -- cgit v0.12