Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #93316

Segmentation Fault with multiple interpreters

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!bcyclone03.am1.xlned.com!bcyclone03.am1.xlned.com!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <florian.ruechel.pythonlist@inexplicity.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'static': 0.03; 'debug': 0.04; 'received:192.168.178': 0.07; 'before.': 0.09; 'callback': 0.09; 'here?': 0.09; 'null);': 0.09; 'received:151': 0.09; 'url:github': 0.09; 'advance': 0.10; 'python': 0.11; 'hey': 0.15; '(but': 0.15; 'interpreter': 0.15; 'weird': 0.15; 'excerpt': 0.16; 'function).': 0.16; 'here).': 0.16; 'libpython': 0.16; 'magic': 0.16; 'pytuple_new': 0.16; 'runtime.': 0.16; 'segfault': 0.16; 'thread.': 0.16; 'where?': 0.16; 'later': 0.16; 'gather': 0.22; 'init': 0.22; 'own.': 0.22; 'void': 0.22; 'code,': 0.23; 'bit': 0.23; 'module': 0.23; 'passing': 0.23; 'this:': 0.23; 'recognized': 0.24; 'written': 0.24; 'header:User-Agent:1': 0.26; 'question': 0.26; 'helpful': 0.27; 'error': 0.27; 'least': 0.27; 'module.': 0.27; 'skip:( 20': 0.28; "i'm": 0.29; 'looks': 0.29; 'yields': 0.29; 'guess': 0.29; 'objects': 0.29; 'starts': 0.29; 'correct': 0.29; "we're": 0.30; 'print': 0.31; 'source': 0.31; 'code': 0.31; 'skip:_ 10': 0.32; 'post': 0.32; 'point': 0.33; 'url:python': 0.33; 'problem': 0.33; 'doubt': 0.33; 'instances': 0.33; 'int': 0.33; 'traceback': 0.33; 'another': 0.34; 'case,': 0.34; 'know.': 0.34; 'this?': 0.34; 'running': 0.34; 'there,': 0.35; 'could': 0.35; 'to:addr:python-list': 0.35; 'along': 0.35; 'instance': 0.35; 'knowledge': 0.35; 'list': 0.35; 'skip:o 20': 0.35; 'but': 0.36; 'being': 0.36; 'list,': 0.36; 'created': 0.36; 'there': 0.36; 'thanks': 0.36; '(and': 0.36; 'loaded': 0.36; 'two': 0.37; 'should': 0.37; 'beyond': 0.37; 'level': 0.37; 'difference': 0.38; 'skip:v 20': 0.38; 'positive': 0.38; 'skip:p 20': 0.38; 'files': 0.38; 'application': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'sure': 0.40; 'subject:with': 0.40; 'received:de': 0.40; 'called': 0.40; 'easy': 0.60; 'addition': 0.60; 'back': 0.61; 'here:': 0.62; 'more': 0.62; 'within': 0.64; 'here': 0.66; 'hints': 0.66; 'behaviors': 0.72; 'increasing': 0.76; '356': 0.84; 'execution.': 0.84; 'florian': 0.84; 'url:master': 0.84; '(full': 0.91; '359': 0.91; '360': 0.91; 'available:': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=simple/simple; d=inexplicity.de; s=inexplicity-dkim; t=1435610604; bh=W/MT1Z6r58ChFYx82uBap63KFNSGsVc4h9W0sgBcjLo=; h=To:From:Subject:Date; b=WC0PKNxyFo+MhxBAIXov8Hddc/bHl8TJgqN59JMPvEm9jE3ntUUghhSAfp1RhxJVX xeTxs+QYrxQvm5oyd5LeMJPgtXRaQncOWq0ZrUYJwXJShsRm09NFZEZnz/qCEph6QI cnbWautnru+ten63Eib06TiHId/oYHhOCyMMftDqsTjsj6JAzfV4WyDRH4GRG4WCtQ iex/4hLzWOdKmlD3Qw7ITPYTXCY0/Wzw6Sy4elRjYRzpU1WWfutUawNCuv7GKhibP0 50AThMeTmf0CXcv1mpyoZU5Wl4sn2F9aQv587et8U2Hl8euB9uFogZxRygP/8Ob7MQ qT4PsocyzfYXA==
To python-list@python.org
From Florian Rüchel <florian.ruechel.pythonlist@inexplicity.de>
Subject Segmentation Fault with multiple interpreters
Date Mon, 29 Jun 2015 22:43:19 +0200
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.0.1
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Mailman-Approved-At Tue, 30 Jun 2015 09:14:57 +0200
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
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.183.1435648498.3674.python-list@python.org> (permalink)
Lines 83
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1435648498 news.xs4all.nl 2861 [2001:888:2000:d::a6]:56217
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 8281
X-Received-Body-CRC 31476767
Xref csiph.com comp.lang.python:93316

Show key headers only | View raw


Hey there,

I'm not sure this is the correct list considering the level of internal
Python knowledge it likely requires. If I should take this to another
list, please let me know.

I have written an application that links against libpython and starts
multiple interpreters within one thread. Beyond that it actually links
against libpython2.7 *and* libpython3.4 (though I doubt that makes a
difference here). In addition to launching my own interpreters I created
a custom C module that can be called from Python (and will be loaded
during my own init function).

The problem is a bit weird and not easy to reproduce. There are two
types of behaviors launched, both running the same C code but diverting
during interpreter runtime. The problem happens only if I start 8
instances of type A and at least one of type B. All instances of type A
start before any instance of type B starts. On the first start of tpye B
the program segfaults. Decreasing the number to 7 yields normal execution.

I could now go along and post a lot of code here and explain the complex
setup but I think it is much more helpful if I can get hints on how to
debug this myself. An excerpt of the traceback (full can be found here:
http://pastebin.com/unAaG6qi)

#0  0x00007f922096cd6a in visit_decref (op=0x7f921d801518
<__hoisted_globals+216>, data=0x0) at Modules/gcmodule.c:360
#1  0x00007f92208aadf2 in meth_traverse (m=0x7f921d4f0d40,
visit=0x7f922096cd52 <visit_decref>, arg=0x0) at Objects/methodobject.c:166
#2  0x00007f922096ce2c in subtract_refs (containers=0x7f9220c108e0
<generations+96>) at Modules/gcmodule.c:385
#3  0x00007f922096dac9 in collect (generation=0x2) at Modules/gcmodule.c:925
#4  0x00007f922096de0a in collect_generations () at Modules/gcmodule.c:1050
#5  0x00007f922096e939 in _PyObject_GC_Malloc (basicsize=0x20) at
Modules/gcmodule.c:1511
#6  0x00007f922096e9d9 in _PyObject_GC_NewVar (tp=0x7f9220bf1540
<PyTuple_Type>, nitems=0x1) at Modules/gcmodule.c:1531
#7  0x00007f92208c7681 in PyTuple_New (size=0x1) at Objects/tupleobject.c:90
...
#58 0x00007f9220953ff7 in initsite () at Python/pythonrun.c:726
#59 0x00007f9220953d94 in Py_NewInterpreter () at Python/pythonrun.c:621
#60 0x00007f921d60024b in prepare_interpreter (argc=0x9, argv=0x387ee70,
m=0x3861e80) at
/home/javex/Thesis/src/shadow-plugin-extras/python/src/python.c:19
#61 0x00007f921d5ff925 in python_new (argc=0x9, argv=0x387ee70,
log=0x421420 <_thread_interface_log>) at
/home/javex/Thesis/src/shadow-plugin-extras/python/src/python.c:160

with the exact point of segfault being this:

355     /* A traversal callback for subtract_refs. */
356     static int
357     visit_decref(PyObject *op, void *data)
358     {
359         assert(op != NULL);
360         if (PyObject_IS_GC(op)) { <---- segfault here
361             PyGC_Head *gc = AS_GC(op);
362             /* We're only interested in gc_refs for objects in the
363              * generation being collected, which can be recognized
364              * because only they have positive gc_refs.

With "op" being:
gdb$ print *op
$4 = {ob_refcnt = 0x1, ob_type = 0x0}

Now I vaguely remember having seen this error before. It *might* have
been that I was passing back Py_None without increasing its reference
(but it later being decref'ed). That case is now solved and I don't
return Py_None at another place.

So the big question is: How do I find out what is happening here? From
what I can gather it looks like GC is cleaning up so I guess I have a
refcount wrong. But which? Where? Can I debug this?

If you think this might help in any case, my source code is also
available:
https://github.com/Javex/shadow-plugin-extras/tree/master/python/src
Here the files python-logging.c, python.c and python-plugin.c are in use
with python.c having most of the magic and python-logging.c being my own
module. Beyond that there's only python code, no more C of my own.

Thanks in advance for any help you can provide. Kind regards,
Florian

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Segmentation Fault with multiple interpreters Florian Rüchel <florian.ruechel.pythonlist@inexplicity.de> - 2015-06-29 22:43 +0200

csiph-web