[issue13103] copy of an asyncore dispatcher causes infinite recursion
STINNER Victor added the comment: This issue has been fixed in Python 3.5 by this change: --- changeset: 90495:2cceb8cb552b parent: 90493:d1a03834cec7 user:Giampaolo Rodola' g.rod...@gmail.com date:Tue Apr 29 02:03:40 2014 +0200 files: Lib/asyncore.py Lib/test/test_asyncore.py Misc/NEWS description: fix isuse #13248: remove previously deprecated asyncore.dispatcher __getattr__ cheap inheritance hack. --- If I understdood correctly, for backward compatibility (and limit risk of regressions), this fix cannot be done in Python 3.4. I close the issue, copy.copy(asyncore.dispatcher()) doesn't crash anymore. -- nosy: +haypo resolution: - fixed status: open - closed versions: +Python 3.5 -Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Xavier de Gaye added the comment: Same problem in 3.4. $ ./python Python 3.4.0a0 (default:e1bee8b09828, Jan 5 2013, 20:29:00) [GCC 4.3.2] on linux Type help, copyright, credits or license for more information. import asyncore a = asyncore.dispatcher() del a.socket a.foo Traceback (most recent call last): File stdin, line 1, in module File ./Lib/asyncore.py, line 410, in __getattr__ retattr = getattr(self.socket, attr) ... File ./Lib/asyncore.py, line 410, in __getattr__ retattr = getattr(self.socket, attr) RuntimeError: maximum recursion depth exceeded while calling a Python object -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Giampaolo Rodola' added the comment: asyncore's __getattr__ horror was scheduled for removal a long ago (3.1 as per issue8483). We can safely remove it for 3.4 and fix the RuntimeError exception above for all the earlier Python versions which are affected. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Changes by Giampaolo Rodola' g.rod...@gmail.com: -- assignee: - giampaolo.rodola ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Xavier de Gaye xdeg...@gmail.com added the comment: The infinite recursion occurs also when running python 3.2 with the extension modules copy, copyreg and asyncore from python 3.1. So it seems this regression is not caused by a modification in these modules. Anyway, the bug is in asyncore. The attached patch fixes it and is more robust than adding the __getstate__ and __setstate__ methods to dispatcher. The patch includes a test case. -- keywords: +patch Added file: http://bugs.python.org/file23317/infinite_recursion_asyncore.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Xavier de Gaye xdeg...@gmail.com added the comment: About why the asyncore bug shows up in python 3.2: The simple test below is ok with python 3.1 but triggers a RuntimeError: maximum recursion depth exceeded... with python 3.2: $ python3.1 Python 3.1.2 (r312:79147, Apr 4 2010, 17:46:48) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. class C: ... def __getattr__(self, attr): ... return getattr(self.foo, attr) ... c = C() hasattr(c, 'bar') False For the reasoning behind this change made in python 3.2, see issue 9666 and the mail http://mail.python.org/pipermail/python-dev/2010-August/103178.html -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: So, in 3.1 hasattr(y, '__setstate__') *did* recurse and hit the limit, but the exception was caught and hasattr returned False? I think I prefer the new behavior... The patch looks good, I would simply have raised AttributeError(name) though. -- nosy: +amaury.forgeotdarc ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Giampaolo Rodola' g.rod...@gmail.com added the comment: IMO, patch should only be applied to Python 3.2. For 3.3 we finally have the chance to get rid of the dispatcher.__getattr__ aberration (see issue 8483) so I say let's just remove it and fix this issue as a consequence. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Amaury Forgeot d'Arc amaur...@gmail.com added the comment: Let's add the test to 3.3 nonetheless. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Xavier de Gaye xdeg...@gmail.com added the comment: So, in 3.1 hasattr(y, '__setstate__') *did* recurse and hit the limit, but the exception was caught and hasattr returned False? This is right. I think I prefer the new behavior... The patch looks good, I would simply have raised AttributeError(name) though. It is fine with me to raise AttributeError(name). Note that when raising AttributeError('socket'), the user gets notified of the exceptions on both 'socket' and 'name'. For example with the patch applied: $ python3 Python 3.2 (r32:88445, Jun 18 2011, 20:30:18) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. import asyncore a = asyncore.dispatcher() del a.socket a.foo Traceback (most recent call last): File asyncore.py, line 415, in __getattr__ retattr = getattr(self.socket, attr) File asyncore.py, line 413, in __getattr__ % self.__class__.__name__) AttributeError: dispatcher instance has no attribute 'socket' During handling of the above exception, another exception occurred: Traceback (most recent call last): File stdin, line 1, in module File asyncore.py, line 418, in __getattr__ %(self.__class__.__name__, attr)) AttributeError: dispatcher instance has no attribute 'foo' -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
New submission from Xavier de Gaye xdeg...@gmail.com: A regression occurs in python 3.2 when doing a copy of an asyncore dispatcher. $ python3.1 Python 3.1.2 (r312:79147, Apr 4 2010, 17:46:48) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. import asyncore, copy copy.copy(asyncore.dispatcher()) asyncore.dispatcher at 0x7fcfb3590e90 $ python3.2 Python 3.2 (r32:88445, Jun 18 2011, 20:30:18) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. import asyncore, copy copy.copy(asyncore.dispatcher()) Traceback (most recent call last): File stdin, line 1, in module File /usr/local/lib/python3.2/copy.py, line 97, in copy return _reconstruct(x, rv, 0) File /usr/local/lib/python3.2/copy.py, line 291, in _reconstruct if hasattr(y, '__setstate__'): File /usr/local/lib/python3.2/asyncore.py, line 410, in __getattr__ retattr = getattr(self.socket, attr) File /usr/local/lib/python3.2/asyncore.py, line 410, in __getattr__ retattr = getattr(self.socket, attr) File /usr/local/lib/python3.2/asyncore.py, line 410, in __getattr__ retattr = getattr(self.socket, attr) RuntimeError: maximum recursion depth exceeded while calling a Python object This occurs after the 'copy' module has created the new instance with __new__(). This new instance does not have the 'socket' attribute, hence the infinite recursion. Adding the following methods to the dispatcher class, fixes the infinite recursion: def __getstate__(self): state = self.__dict__.copy() return state def __setstate__(self, state): self.__dict__.update(state) But it does not explain why the recursion occurs in 3.2 and not in 3.1. -- components: Extension Modules messages: 144925 nosy: xdegaye priority: normal severity: normal status: open title: copy of an asyncore dispatcher causes infinite recursion type: behavior versions: Python 3.2 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue13103] copy of an asyncore dispatcher causes infinite recursion
Changes by Ezio Melotti ezio.melo...@gmail.com: -- nosy: +giampaolo.rodola, josiahcarlson, stutzbach stage: - test needed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue13103 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com