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


Groups > comp.lang.python > #196408

Re: PyGILState_Ensure() deadlocks, why?

Path csiph.com!news.mixmin.net!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From Barry Scott <barry@barrys-emacs.org>
Newsgroups comp.lang.python
Subject Re: PyGILState_Ensure() deadlocks, why?
Date Mon, 8 Jul 2024 09:33:39 +0100
Lines 43
Message-ID <mailman.21.1720428030.2981.python-list@python.org> (permalink)
References <DGC1c0YSrMcV0n6rNNeplHySXzBWUfTUwJbBVPgOocO1evufk5MKe8QWWEzO6Zj5-_0VrJJbK3OpB5-vrvMdDRKITiZrvq0RMY69IND05u4=@protonmail.ch> <BFD66552-780D-4B47-BE26-AA01988E3D07@barrys-emacs.org> <3FAD214C-6797-4A63-8F48-6E436D36A2D2@barrys-emacs.org>
Mime-Version 1.0 (Mac OS X Mail 16.0 \(3774.600.62\))
Content-Type text/plain; charset=us-ascii
Content-Transfer-Encoding quoted-printable
X-Trace news.uni-berlin.de 7pTsmNhiu5rJ0jwrCmHjrwGicOoFyfTk3wqu21R4B6hQ==
Cancel-Lock sha1:JP6HzAwE6eO20QDLWKUcfD3C4oY= sha256:66qYWpvqYlPmKcHzjjCs6l3wwUL226lzu49QOtWl5XY=
Return-Path <barry@barrys-emacs.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
Authentication-Results mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'jul': 0.04; 'thread': 0.05; 'python.': 0.08; 'cc:addr:python-list': 0.09; 'from:addr:barry': 0.09; 'received:217.70': 0.09; 'received:217.70.178': 0.09; 'received:gandi.net': 0.09; 'received:mail.gandi.net': 0.09; 'subject:skip:P 10': 0.09; 'threads': 0.09; 'cc:no real name:2**0': 0.14; 'barry': 0.16; 'c++': 0.16; 'enforcing': 0.16; 'ensuring': 0.16; 'from:addr :barrys-emacs.org': 0.16; 'from:name:barry scott': 0.16; 'gil': 0.16; 'init': 0.16; 'interesting.': 0.16; 'message-id:@barrys- emacs.org': 0.16; 'subject:() ': 0.16; 'url:head': 0.16; 'url:tree': 0.16; 'wrote:': 0.16; 'python': 0.16; 'says': 0.17; 'cc:addr:python.org': 0.20; 'machine': 0.22; 'code': 0.23; 'cc:2**1': 0.23; 'classes': 0.26; 'leave': 0.27; 'project.': 0.27; 'email addr:python.org&gt;': 0.28; 'wrong': 0.28; 'think': 0.32; 'python-list': 0.32; 'but': 0.32; "i'm": 0.33; 'there': 0.33; 'release': 0.34; 'header:In-Reply-To:1': 0.34; 'missing': 0.37; 'main': 0.37; 'use': 0.39; 'block': 0.39; 'still': 0.40; 'wants': 0.40; 'tell': 0.60; 'research': 0.64; 'your': 0.64; 'well': 0.65; 'received:217': 0.67; 'url-ip:104.18/16': 0.67; 'right': 0.68; 'url:net': 0.68; 'front': 0.70; 'rules': 0.70; 'you.': 0.71; 'longer': 0.71; 'manage': 0.73; 'near': 0.76; 'acquire': 0.84; 'extra': 0.84; 'email name:&lt;python-list': 0.84; 'saves': 0.84; 'url:sourceforge': 0.84; 'url:p': 0.88; 'url:source': 0.89
In-Reply-To <BFD66552-780D-4B47-BE26-AA01988E3D07@barrys-emacs.org>
X-Mailer Apple Mail (2.3774.600.62)
X-GND-Sasl barry@barrys-emacs.org
X-Content-Filtered-By Mailman/MimeDel 2.1.39
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.39
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 <https://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>
X-Mailman-Original-Message-ID <3FAD214C-6797-4A63-8F48-6E436D36A2D2@barrys-emacs.org>
X-Mailman-Original-References <DGC1c0YSrMcV0n6rNNeplHySXzBWUfTUwJbBVPgOocO1evufk5MKe8QWWEzO6Zj5-_0VrJJbK3OpB5-vrvMdDRKITiZrvq0RMY69IND05u4=@protonmail.ch> <BFD66552-780D-4B47-BE26-AA01988E3D07@barrys-emacs.org>
Xref csiph.com comp.lang.python:196408

Show key headers only | View raw



> On 7 Jul 2024, at 23:21, Barry via Python-list <python-list@python.org> wrote:
> 
> 
> 
>> On 7 Jul 2024, at 22:09, Tomas Ukkonen via Python-list <python-list@python.org> wrote:
>> 
>>    Py_Initialize();
> 
> You also need to tell python to init threading.

I'm in front of my dev machine now and checking up on threading.

There is no longer any extra init for threads required.

> I think you are missing more python setup code before you can use threads.
> Also i think you need to tell python that your thread wants to call into python.
> But I an not near my dev system to research this for you.

You are right to use PyGILState_Ensure()

But as MRAB says the main thread is holding the GIL.

> 
> I have code to use python from C++ in my pysvn project.
> See the code starting a line 354 in https://sourceforge.net/p/pysvn/code/HEAD/tree/trunk/pysvn/Extension/Source/pysvn.cpp
> That saves the thread state and restores it.

You still might find the classes I wrong to manage GIL acquire and release interesting.
I have the C++ type system enforcing the rules of acquire and release.
As well as RAII ensuring never to leave a block with the GIL in the wrong state.

Barry

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


Thread

Re: PyGILState_Ensure() deadlocks, why? Barry Scott <barry@barrys-emacs.org> - 2024-07-08 09:33 +0100

csiph-web