Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #57: Groundskeepers stole the root password


comp / comp.lang.python / PyGILState_Ensure() deadlocks, why?

SubjectAuthor
o PyGILState_Ensure() deadlocks, why?Tomas Ukkonen

1
Subject: PyGILState_Ensure() deadlocks, why?
From: Tomas Ukkonen
Newsgroups: comp.lang.python
Date: Sun, 7 Jul 2024 19:24 UTC
References: 1
Attachments: "signature.asc" (application/pgp-signature)
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: tomas.ukkonen@protonmail.ch (Tomas Ukkonen)
Newsgroups: comp.lang.python
Subject: PyGILState_Ensure() deadlocks, why?
Date: Sun, 07 Jul 2024 19:24:04 +0000
Lines: 103
Message-ID: <mailman.11.1720386402.2981.python-list@python.org>
References: <y-6AMIAbWkvLII_tfcbRs5NtbKgQRos3XlZ83qbGCwuq7RSQJBGniGJEn4Nzwr_iVQfJOdvLVzOycTR0V-F-pDKt2rNPj3cHmFVY06vNQnI=@protonmail.ch>
Mime-Version: 1.0
Content-Type: multipart/signed; protocol="application/pgp-signature";
micalg=pgp-sha256;
boundary="------ce3546e9f767c4f407662caac2a8083d8c4baf7a1f1fc141736db6f000bc5b55";
charset=utf-8
X-Trace: news.uni-berlin.de FKtOrZhAPRNTmi3ODBmFpgqAZEHM0ho26ChnM4i6O8AQ==
Cancel-Lock: sha1:gECVaiofmvM6379XtHvCU+gosLk= sha256:Vs636oROhxm+9KO3U1PztuDy8X+pm6/uJLiWR63yokg=
Return-Path: <tomas.ukkonen@protonmail.ch>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=protonmail.ch header.i=@protonmail.ch header.b=jJpR0a7s;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.000
X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'content-
type:multipart/signed': 0.05; 'thread': 0.05; 'content-
type:application/pgp-signature': 0.09; 'filename:fname piece:asc':
0.09; 'filename:fname piece:signature': 0.09;
'filename:fname:signature.asc': 0.09; 'int': 0.09; 'linux': 0.09;
'skip:` 10': 0.09; 'subject:skip:P 10': 0.09; 'threads': 0.09;
'ubuntu': 0.09; '#include': 0.16; '&lt;': 0.16; 'c++': 0.16;
'content-disposition:attachment; filename="signature.asc"': 0.16;
'gil': 0.16; 'gnu/linux': 0.16; 'initialize': 0.16; 'interpreter':
0.16; 'long-running': 0.16; 'main()': 0.16; 'subject:() ': 0.16;
'vector': 0.16; 'void': 0.16; 'python': 0.16; 'api': 0.17;
'to:addr:python-list': 0.20; 'code': 0.23; 'skip:p 30': 0.23;
'to:name:python-list@python.org': 0.24; 'received:185.70': 0.26;
'received:protonmail.ch': 0.26; 'task': 0.26; 'release': 0.34;
'received:ch': 0.35; 'following': 0.35; 'skip:t 40': 0.64;
'content-type:multipart/mixed': 0.68; 'received:185': 0.71;
'header:Received:2': 0.84
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.ch;
s=protonmail3; t=1720380248; x=1720639448;
bh=8kkRbFLAJcKPou5dYM8yBDskAATb/w500GRGvm0922E=;
h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date:
Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector;
b=jJpR0a7smrMC5oa/7NF0rCxpYglspYlQbTXrFErUk0H3kRwGq6DrX8Qne3nQCq363
rooiyifal4FdCRJ86BxsOrSz1aHsPykvIi+8izO10g4MxhVhODri0Ar8r87oonB7QW
xRKbcOjDlV+4wNqdL+ASTyYgFEn58ROPy9mlOhf1BU+hUgV8io4oAO2HPFIMz3zoG6
W9aj/4iyAg4ysZ+xLZQMlajrxh3vdy1ianLGm2ILqP5F/KPqw4omm7cU2PpR9kknOS
na4kYbc0BcLCgm3gndZf8kdvTgsmIPvDjEnjfQnYAeFIUOpWNeUTPoSBAwCihaJLVH
mg+ybOhvu2g+Q==
Feedback-ID: 809323:user:proton
X-Pm-Message-ID: 7b589e65dd766691116ab9c0b1936ade8acab311
X-Mailman-Approved-At: Sun, 07 Jul 2024 17:06:42 -0400
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: <y-6AMIAbWkvLII_tfcbRs5NtbKgQRos3XlZ83qbGCwuq7RSQJBGniGJEn4Nzwr_iVQfJOdvLVzOycTR0V-F-pDKt2rNPj3cHmFVY06vNQnI=@protonmail.ch>
View all headers

Hello
Is this python c api bug? The following C++ code (g++) deadlocks on Ubuntu Linux.

/* * This code deadlocks on python3-dev 3.12.3 (ubuntu 24.04 lts)
 *
 * g++ python_thread_test.cpp `python3-config --cflags --libs --embed`
 * ./a.out
 *
 * uname:
 * Linux softice 6.8.0-36-generic SMP PREEMPT_DYNAMIC x86_64 GNU/Linux
 */

#include <Python.h>
#include <thread>
#include <vector>
#include <iostream>

void perform_long_operation() {
    // Simulate a long-running task
    std::this_thread::sleep_for(std::chrono::seconds(5));
}

void thread_function() {
    // Ensure this thread has the GIL
    PyGILState_STATE gstate = PyGILState_Ensure();

    // Execute some Python code
    PyRun_SimpleString("print('Hello from std::thread!')");

    // Release the GIL for long operation
    Py_BEGIN_ALLOW_THREADS
    perform_long_operation();
    Py_END_ALLOW_THREADS

    // Re-acquire the GIL and execute more Python code
    gstate = PyGILState_Ensure();
    PyRun_SimpleString("print('Thread operation completed!')");

    // Release the GIL
    PyGILState_Release(gstate);
}

int main() {
    // Initialize the Python Interpreter
    Py_Initialize();

    // Create a vector of threads
    std::vector<std::thread> threads;

    // Launch threads
    for (int i = 0; i < 5; ++i) {
        threads.push_back(std::thread(thread_function));
    }

    // Join threads
    for (auto& t : threads) {
        t.join();
    }

    // Finalize the Python Interpreter
    Py_Finalize();

    return 0;
}

Tomas Ukkonen

Attachments: "signature.asc" (application/pgp-signature)
1

rocksolid light 0.9.8
clearnet tor