Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

<sangr> home is where the highest bandwidth is


devel / comp.lang.python / Re: PyGILState_Release called twice in embedded application

SubjectAuthor
o Re: PyGILState_Release called twice in embedded applicationArnaud Loonstra

1
Re: PyGILState_Release called twice in embedded application

<mailman.2388.1679582087.20444.python-list@python.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=26964&group=comp.lang.python#26964

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: arnaud@sphaero.org (Arnaud Loonstra)
Newsgroups: comp.lang.python
Subject: Re: PyGILState_Release called twice in embedded application
Date: Thu, 23 Mar 2023 15:34:45 +0100
Lines: 41
Message-ID: <mailman.2388.1679582087.20444.python-list@python.org>
References: <a67f561c-72b0-525c-5411-0463e914e810@sphaero.org>
<0709E328-8035-4B81-ADE1-8170834DBB8F@barrys-emacs.org>
<58852f4d-2654-a8be-a317-5219e30e21cf@sphaero.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de ZLDGwsk13l6wf2XQ2YO3MQvd4mPcbv5iBy0BH1nvTLRw==
Return-Path: <arnaud@sphaero.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.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'url-ip:140.82/16': 0.03;
'3.8': 0.05; 'issue.': 0.05; 'thread': 0.05; 'mar': 0.07;
'suggestion': 0.07; 'cc:addr:python-list': 0.09; 'myself.': 0.09;
'subject:embedded': 0.09; 'subject:skip:P 10': 0.09; 'url:github':
0.14; 'import': 0.15; 'url-ip:140/8': 0.15; '(7)': 0.16; '(so':
0.16; 'barry': 0.16; 'cc:name:python list': 0.16; 'cpython': 0.16;
'extensions': 0.16; 'gil': 0.16; 'subject:application': 0.16;
'welcomed': 0.16; 'wrote:': 0.16; 'python': 0.16; 'code.': 0.17;
'calls': 0.19; 'cc:addr:python.org': 0.20; 'all,': 0.20; 'issue':
0.21; "i've": 0.22; 'closed': 0.22; 'code': 0.23; "i'd": 0.24;
'extension': 0.25; 'cc:2**0': 0.25; 'party': 0.26; 'requests':
0.28; 'header:User-Agent:1': 0.30; 'module': 0.31; "doesn't":
0.32; 'fine.': 0.32; 'happening': 0.32; 'but': 0.32; "i'm": 0.33;
'header:In-Reply-To:1': 0.34; 'running': 0.34; 'close': 0.35;
'using': 0.37; 'received:192.168': 0.37; 'adding': 0.39; 'place.':
0.40; 'acquiring': 0.61; 'finished': 0.64; 'worked': 0.67;
'prevent': 0.67; 'away': 0.67; 'closing': 0.69; '3rd': 0.81;
'scott': 0.84; 'surprised': 0.84; 'caused': 0.86; 'received:45':
0.86
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Content-Language: en-US
In-Reply-To: <0709E328-8035-4B81-ADE1-8170834DBB8F@barrys-emacs.org>
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: <58852f4d-2654-a8be-a317-5219e30e21cf@sphaero.org>
X-Mailman-Original-References: <a67f561c-72b0-525c-5411-0463e914e810@sphaero.org>
<0709E328-8035-4B81-ADE1-8170834DBB8F@barrys-emacs.org>
 by: Arnaud Loonstra - Thu, 23 Mar 2023 14:34 UTC

On 23-03-2023 13:33, Barry Scott wrote:
>
>
>> On 23 Mar 2023, at 08:46, Arnaud Loonstra <arnaud@sphaero.org> wrote:
>>
>> Hi all,
>>
>> I'm running in a crash due to a ResourceWarning (some socket is not closed in a used module) after calling PyGILState_Release.
>>
>> I'm running Python in a native thread (so a thread created by C not Python). I'm acquiring the GIL through PyGILState_Ensure before doing any CPYthon calls and releasing when finished using PyGILState_Release.
>>
>> This has worked fine. But now I'm using a python module (openai) which doesn't close its socket correctly which results in a ResourceWarning which triggers an assert.
>>
>> In the backtrace (below) I can see PyGILState_Release is called again. (7) while I've already called it (126).
>>
>> I can make the crash go away by adding
>>
>> import warnings
>> warnings.simplefilter("ignore", ResourceWarning)
>>
>> to my python code. But I'd rather prevent this from happening in the first place.
>>
>> Any suggestion very welcomed cause I'm puzzled.
>
> What 3rd party C extension are you running with?
> I'd be surprised if the cpython code was the issue.
>
> Barry

I'm not using any 3rd party extension myself. But the issue is caused by
the openai module using the requests module which is not closing sockets:

https://github.com/openai/openai-python/issues/140

I'm not aware what C extensions they might use.

Btw, I've tested this with python 3.8 and 3.11.2.

Rg,

Arnaud


devel / comp.lang.python / Re: PyGILState_Release called twice in embedded application

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor