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


Groups > comp.lang.python > #2618

Re: PyThreadState_Swap crash

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!news-transit.tcx.org.uk!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <philip@semanchuk.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'bug': 0.02; 'debug': 0.03; '(using': 0.05; 'interpreter': 0.07; 'url:bugs': 0.07; 'python': 0.07; 'description,': 0.09; 'internally': 0.09; 'to:name:python list': 0.09; 'api': 0.11; 'am,': 0.14; 'wrote:': 0.14; 'crashes': 0.16; 'received:mindspring.com': 0.16; '"python': 0.16; 'obviously': 0.20; 'maybe': 0.21; 'code': 0.22; 'header:In-Reply- To:1': 0.22; 'skip:( 30': 0.24; 'calling': 0.25; "i'm": 0.26; "doesn't": 0.28; 'skip:p 30': 0.29; 'supports': 0.29; 'problem': 0.29; 'comment': 0.30; 'one)': 0.31; "they'll": 0.31; 'threads': 0.31; 'second': 0.31; "can't": 0.31; 'to:addr:python-list': 0.32; 'another': 0.32; "i've": 0.33; 'creates': 0.33; 'sorry': 0.33; 'created': 0.33; 'several': 0.33; 'sometimes': 0.33; 'uses': 0.34; 'using': 0.34; 'got': 0.34; 'there': 0.35; 'suggestion': 0.35; 'point': 0.35; 'quite': 0.36; 'possibility': 0.36; 'charset:us- ascii': 0.36; 'url:python': 0.37; 'run': 0.37; 'apr': 0.38; 'thread': 0.38; 'but': 0.38; 'url:org': 0.38; 'used': 0.38; 'subject:skip:P 10': 0.39; 'to:addr:python.org': 0.39; 'header :Mime-Version:1': 0.39; 'received:24': 0.39; 'solution': 0.40; "it's": 0.40; 'might': 0.40; 'philip': 0.60; 'you.': 0.61; 'header :Message-Id:1': 0.62; 'found.': 0.65; 'luck': 0.71; 'received:69.73': 0.84
Content-Type text/plain; charset=us-ascii
Mime-Version 1.0 (Apple Message framework v1082)
Subject Re: PyThreadState_Swap crash
From Philip Semanchuk <philip@semanchuk.com>
In-Reply-To <2cad664c-f054-47ba-8cb5-8b9073a040af@e8g2000vbz.googlegroups.com>
Date Mon, 4 Apr 2011 21:15:20 -0400
Content-Transfer-Encoding quoted-printable
References <2cad664c-f054-47ba-8cb5-8b9073a040af@e8g2000vbz.googlegroups.com>
To Python list <python-list@python.org>
X-Mailer Apple Mail (2.1082)
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - deimos.nocdirect.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - semanchuk.com
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.30.1301966127.9059.python-list@python.org> (permalink)
Lines 53
NNTP-Posting-Host 82.94.164.166
X-Trace 1301966127 news.xs4all.nl 41114 [::ffff:82.94.164.166]:59518
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:2618

Show key headers only | View raw


On Apr 4, 2011, at 9:08 AM, Wiktor Adamski wrote:

> I have 2 threads in C code using python 2.5.2. First thread creates
> new interpreter (i need several interpreters but those 2 threads use
> only one) like that:
> 
> PyEval_AcquireLock();
> threadState = Py_NewInterpreter();
> PyThreadState_Swap(threadState);
> 
> // calling python API
> 
> PyThreadState_Swap(NULL);
> PyEval_ReleaseLock();
> 
> Second thread uses interpreter created in first thread:
> 
> PyEval_AcquireLock();
> PyThreadState_Swap(threadState);
> 
> and sometimes PyThreadState_Swap crashes in debug build
> (PyGILState_GetThisThreadState() returns garbage). In release build
> that code doesn't run and so far no other problem was found.
> I call PyEval_InitThreads() at the begining of program and every
> PyEval_AcquireLock() has PyEval_ReleaseLock().
> 
> Am I allowed to use the same threadState in different threads?
> If I am, is there another problem in my code?
> Or maybe it's a bug in python - acording to documentation "Python
> still supports the creation of additional interpreters (using
> Py_NewInterpreter()), but mixing multiple interpreters and the
> PyGILState_*() API is unsupported." - I don't use PyGILState_ but it's
> used internally in PyThreadState_Swap(). I also don't use
> PyEval_RestoreThread() - comment sugests that crashing code is present
> because possibility of calling from PyEval_RestoreThread().

Hi Wiktor,
I'm sorry I don't have a solution or even a suggestion for you. I just wanted to point out that PyEval_AcquireLock() and PyEval_ReleaseLock() were recently deprecated:
http://bugs.python.org/issue10913

Obviously they'll be around for quite a while longer but given the ominous-but-vague warning in issue10913's description, you might want to stay away from them. It's frustrating for me because I've got code I can't get to work without them.

Good luck
Philip


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


Thread

PyThreadState_Swap crash Wiktor Adamski <BardzoTajneKonto@interia.pl> - 2011-04-04 06:08 -0700
  Re: PyThreadState_Swap crash Philip Semanchuk <philip@semanchuk.com> - 2011-04-04 21:15 -0400

csiph-web