Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #72809
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.albasani.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <Nikolaus@rath.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'preferred.': 0.05; 'problem:': 0.07; 'python3': 0.07; 'source.': 0.07; '"c"': 0.09; 'derived': 0.09; 'executed': 0.09; 'def': 0.12; 'thread': 0.14; 'components.': 0.16; 'destructor.': 0.16; 'fingerprint:': 0.16; 'fruit': 0.16; 'garbage': 0.16; 'gpg': 0.16; 'intervening': 0.16; 'module': 0.19; 'stack': 0.19; 'example': 0.22; 'import': 0.22; 'id:': 0.23; 'header:User-Agent:1': 0.23; 'looks': 0.24; 'skip:" 30': 0.26; 'pass': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'statement': 0.30; '(which': 0.31; 'code': 0.31; '13,': 0.31; 'routine': 0.31; 'trace': 0.31; 'writes:': 0.31; 'file': 0.32; 'class': 0.32; 'run': 0.32; '(e.g.': 0.33; 'minimal': 0.33; 'skip:# 10': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'case,': 0.35; 'there': 0.35; 'really': 0.36; 'object,': 0.36; 'next': 0.36; 'method': 0.36; 'subject:?': 0.36; 'should': 0.36; 'list': 0.37; 'easily': 0.37; 'being': 0.38; 'server': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'called': 0.40; 'skip:t 30': 0.61; 'mentioned': 0.61; 'numbers': 0.61; 'skip:* 10': 0.61; 'skip:n 10': 0.64; 'places': 0.64; 'by:': 0.65; 'close': 0.67; 'obvious': 0.74; '_bootstrap': 0.84; 'flies': 0.84; 'self.run()': 0.84; 'encrypted': 0.91 |
| From | Nikolaus Rath <Nikolaus@rath.org> |
| To | python-list@python.org |
| Subject | Re: Missing stack frames? |
| References | <87fvjlv22v.fsf@vostro.rath.org> <CAPTjJmqzgZnziz3+yZb-4bsYtfxT2AG5HQ9Pb3Ya8AWDW8+oHA@mail.gmail.com> <87oay8pobi.fsf@rath.org> <87r433ri00.fsf@handshake.de> |
| Mail-Copies-To | never |
| Mail-Followup-To | python-list@python.org |
| Date | Thu, 05 Jun 2014 19:16:06 -0700 |
| In-Reply-To | <87r433ri00.fsf@handshake.de> (dieter@handshake.de's message of "Thu, 05 Jun 2014 08:24:31 +0200") |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux) |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.10801.1402020972.18130.python-list@python.org> (permalink) |
| Lines | 88 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1402020972 news.xs4all.nl 2854 [2001:888:2000:d::a6]:41357 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:72809 |
Show key headers only | View raw
dieter <dieter@handshake.de> writes:
[...]
> Someone else already mentioned that the "close" call
> can come from a destructor. Destructors can easily be called
> at not obvious places (e.g. "s = C(); ... x = [s for s in ...]";
> in this example the list comprehension calls the "C" destructor
> which is not obvious when one looks only locally).
> The destructor calls often have intervening C code (which
> one does not see). However, in your case, I do not see
> why the "cgi" module should cause a destructor call of one
> of your server components.
Paul, dieter, you are my heroes. It was indeed an issue with a
destructor. It turns out that the io.RawIOBase destructor calls
self.close(). If the instance of a derived class is part of a reference
cycle, it gets called on the next routine run of the garbage
collector -- with the stack trace originating at whatever statement was
last executed before the gc run.
The following minimal example reproduces the problem:
#!/usr/bin/env python3
import io
import traceback
import threading
class Container:
pass
class InnocentVictim(io.RawIOBase):
def close(self):
print('close called in %s by:'
% threading.current_thread().name)
traceback.print_stack()
def busywork():
numbers = []
for i in range(500):
o = Container()
o.l = numbers
numbers.append(o)
if i % 87 == 0:
numbers = []
l = [ InnocentVictim() ]
l[0].cycle = l
del l
t = threading.Thread(target=busywork)
t.start()
t.join()
If you run this, you could things like:
close called in Thread-1 by:
File "/usr/lib/python3.4/threading.py", line 888, in _bootstrap
self._bootstrap_inner()
File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
self.run()
File "/usr/lib/python3.4/threading.py", line 868, in run
self._target(*self._args, **self._kwargs)
File "./test.py", line 18, in busywork
o = Container()
File "./test.py", line 13, in close
traceback.print_stack()
Ie, a method being called by a thread that doesn't have access to the
object, and without any reference to the call in the source.
I am left wondering:
- Is there really a point in the RawIOBase destructor calling close?
- Is there some way to make the call stack for destructors less confusing?
Best,
-Nikolaus
--
GPG encrypted emails preferred. Key id: 0xD113FCAC3C4E599F
Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
»Time flies like an arrow, fruit flies like a Banana.«
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Missing stack frames? Nikolaus Rath <Nikolaus@rath.org> - 2014-06-05 19:16 -0700
csiph-web