Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

Your talents will be recognized and suitably rewarded.


comp / comp.lang.python / Re: Python crash together with threads

SubjectAuthor
o Re: Python crash together with threadsLeft Right

1
Subject: Re: Python crash together with threads
From: Left Right
Newsgroups: comp.lang.python
Date: Thu, 3 Oct 2024 21:01 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!not-for-mail
From: olegsivokon@gmail.com (Left Right)
Newsgroups: comp.lang.python
Subject: Re: Python crash together with threads
Date: Thu, 3 Oct 2024 23:01:53 +0200
Lines: 72
Message-ID: <mailman.33.1727990609.3018.python-list@python.org>
References: <CAASeUHoPO8kd0j7Uwn2T6R52W+7en8Q7DQDbRa1_6pQurRc-Dg@mail.gmail.com>
<CAJQBtgm6rcePWraqJwyH9k=P9wK5XDSxkh4yU6jQdi8M5SxSBQ@mail.gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de m7eccIKaSZquk1VnfOJ6VAQ7ryI65MPp5ObmYlUXAbkw==
Cancel-Lock: sha1:Z9XCKt3zTk0sV2kv1XD+CTHFC1Y= sha256:S3AhaPBeVsYZnAoe9iAUIJFnkl+Usx2kXD7Vq8beu/U=
Return-Path: <olegsivokon@gmail.com>
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=gmail.com header.i=@gmail.com header.b=NXoB7tq/;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.012
X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'thread': 0.05;
'architecture': 0.07; 'that?': 0.07; 'python.': 0.08; 'cc:addr
:python-list': 0.09; 'forced': 0.09; 'skip:_ 20': 0.09;
'subject:Python': 0.12; 'cc:no real name:2**0': 0.14;
'url:mailman': 0.15; 'memory': 0.15; 'that.': 0.15; '#endif':
0.16; '2024': 0.16; 'arithmetic': 0.16; 'clues': 0.16; 'mitigate':
0.16; 'permanently.': 0.16; 'received:mail-qv1-xf2e.google.com':
0.16; 'scenario,': 0.16; 'static': 0.16; 'thread.': 0.16; 'void':
0.16; 'wrote:': 0.16; 'python': 0.16; 'probably': 0.17;
'cc:addr:python.org': 0.20; 'skip:_ 10': 0.22; 'code': 0.23;
'(and': 0.25; 'url-ip:188.166.95.178/32': 0.25; 'url-
ip:188.166.95/24': 0.25; 'url:listinfo': 0.25; 'cc:2**0': 0.25;
'url-ip:188.166/16': 0.25; 'function': 0.27; 'skip:_ 40': 0.31;
'url-ip:188/8': 0.31; 'program': 0.31; 'here,': 0.32; 'objects':
0.32; 'python-list': 0.32; 'message-id:@mail.gmail.com': 0.32;
'but': 0.32; 'hold': 0.33; 'requires': 0.34; 'header:In-Reply-
To:1': 0.34; 'received:google.com': 0.34; 'fine': 0.35;
'from:addr:gmail.com': 0.35; 'cases': 0.36; 'possibly': 0.36;
'main': 0.37; 'using': 0.37; "it's": 0.37; 'skip:_ 30': 0.37;
'quite': 0.39; 'shared': 0.39; 'wed,': 0.39; 'happen': 0.40;
'inline': 0.61; 'above': 0.62; 'here': 0.62; 'skip:o 20': 0.63;
"you'd": 0.64; 'your': 0.64; 'dedicated': 0.65; 'parts': 0.65;
'right': 0.68; 'skip:/ 10': 0.69; 'virtually': 0.69; '1st': 0.78;
'states': 0.80; 'happens': 0.84; 'allocated': 0.84; 'divine':
0.84; 'flows': 0.84; 'pointer': 0.84; 'whats': 0.84; 'newly':
0.93; 'skip:q 20': 0.95
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20230601; t=1727989326; x=1728594126; darn=python.org;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:from:to:cc:subject:date
:message-id:reply-to;
bh=FH3pZZffV+O01DBXb6XzSP4KaXmyYLxnonGd2Enr068=;
b=NXoB7tq/dky9th5dHFZbYsJF1eLfaH0X6iQ+TwyPIxI4J4MHuaU3G17mZl95tQ2e6C
XGSIdrZM7FiPYQ9vl+v014iVmUPhFC/p/gqxfmjSyDIea4WKNSYKkfNpusBGTVk3g3mp
Y2lp/6O7Ac8qrZzNHvmMaaQiWn56Q/RtWht5RVA4fkTN4fNWhNQ1Gg3cUgxLuh5lth/5
LV/dcnUzjjHGoACZrEFaBzquoMfYiTRwhFSRx77Dml4UWrzRZ+TI/LpeT+m1xZIeRxIB
CXrzNCJGgHjtE7aO4s8rxkDOd8eTHqDE5ajGCGKLpJQhjab6cjF3Pw8bMxfrdrH38F1X
X+Tw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20230601; t=1727989326; x=1728594126;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:x-gm-message-state:from:to:cc
:subject:date:message-id:reply-to;
bh=FH3pZZffV+O01DBXb6XzSP4KaXmyYLxnonGd2Enr068=;
b=AzTCW25+7cXYCfufdOUkpvovzguZ2+Eka3toctU8LSp4X7Htazdpz6lqIC/ZqnDct0
tQjCXgoO8oq6NxtUvfzzlgylIJ+tqrPoH/Pb1fapqyuWpq5zqMZDu/qdfjs6caA+Tf7J
KVbJZf+MWF6BNZPhSoqSseM5STz9bGOGsccNm1SMmhJTg2bEm7aNMMrl0KXzq+XGtgnk
tdfo96V4W8EJbh1rkq03WiYWfslX2a7rUSgra1YULeOq6esfjrkvwfewCd0oj9Ikyvnu
DPMkJ9QvThKBOWz+KDaqEB4miD40jaCMR6HCrqKBknDh59HFioAit9M89UFat2HsLJ3B
+luQ==
X-Gm-Message-State: AOJu0Yy0E4+Tk+dp+Ojaltqd8fJj7Bj6bIGnB3pmWH9ep85BG+kPPmpq
kple2OFvUTzsR3mdbspYAuixUAan/D4Gi1OD6xMkE7UcqohP0kwkp1d0pyg+cakayAFa8i3BqGZ
fDTlXkgCURS+Yh6m1h8KNe/uKNouM3vhp
X-Google-Smtp-Source: AGHT+IGTCmI+K2ND4/Uj3Wmd2aYvDow5MeyCfau688KgijtfrY/4XZXHSzBWq1d3aH3Z1BHAptWLu2gIYRk//CtQ3jw=
X-Received: by 2002:a05:6214:3214:b0:6cb:49d2:c700 with SMTP id
6a1803df08f44-6cb9ae038b7mr8475336d6.22.1727989325782; Thu, 03 Oct 2024
14:02:05 -0700 (PDT)
In-Reply-To: <CAASeUHoPO8kd0j7Uwn2T6R52W+7en8Q7DQDbRa1_6pQurRc-Dg@mail.gmail.com>
X-Mailman-Approved-At: Thu, 03 Oct 2024 17:23:27 -0400
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: <CAJQBtgm6rcePWraqJwyH9k=P9wK5XDSxkh4yU6jQdi8M5SxSBQ@mail.gmail.com>
X-Mailman-Original-References: <CAASeUHoPO8kd0j7Uwn2T6R52W+7en8Q7DQDbRa1_6pQurRc-Dg@mail.gmail.com>
View all headers

> whereas I am quite sure that program flows do not overlap.

You can never be sure of this in Python. Virtually all objects in
Python are allocated on heap, so instantiating integers, doing simple
arithmetic etc. -- all of this requires synchronization because it
will allocate memory for a shared pool.

The description of _PyThreadState_GET states that callers must hold
GIL. Does your code do that? It's not possible to divine that from the
stack trace, but you'd probably know that.

On Wed, Oct 2, 2024 at 3:29 PM Guenther Sohler via Python-list
<python-list@python.org> wrote:
>
> My Software project is working fine in most of the cases
> (www.pythonscad.org)
> however I am right now isolating a scenario, which makes it crash
> permanently.
>
> It does not happen with Python 3.11.6 (and possibly below), it happens with
> 3.12 and above
> It does not happen when not using Threads.
>
> However due to the architecture of the program I am forced to evaluate some
> parts in main thread and some parts in a dedicated Thread. The Thread is
> started with QThread(QT 5.0)
> whereas I am quite sure that program flows do not overlap.
>
> When I just execute my 1st very simple Python function inside the newly
> created thread, like:
>
> PyObject *a = PyFloat_FromDouble(3.3);
>
> my program crashes with this Stack trace
>
> 0 0x00007f6837fe000f in _PyInterpreterState_GET () at
> ./Include/internal/pycore_pystate.h:179
> #1 get_float_state () at Objects/floatobject.c:38
> #2 PyFloat_FromDouble (fval=3.2999999999999998) at
> Objects/floatobject.c:136
> #3 0x00000000015a021f in python_testfunc() ()
> #4 0x0000000001433301 in CGALWorker::work() ()
> #5 0x0000000000457135 in CGALWorker::qt_static_metacall(QObject*,
> QMetaObject::Call, int, void**) ()
> #6 0x00007f68364d0f9f in void doActivate<false>(QObject*, int, void**) ()
> at /lib64/libQt5Core.so.5
> #7 0x00007f68362e66ee in QThread::started(QThread::QPrivateSignal) () at
> /lib64/libQt5Core.so.5
> #8 0x00007f68362e89c4 in QThreadPrivate::start(void*) () at
> /lib64/libQt5Core.so.5
> #9 0x00007f6835cae19d in start_thread () at /lib64/libc.so.6
> #10 0x00007f6835d2fc60 in clone3 () at /lib64/libc.so.6
>
>
> I suspect, that this is a Null pointer here
> See also _PyInterpreterState_Get()
> and _PyGILState_GetInterpreterStateUnsafe(). */
> static inline PyInterpreterState* _PyInterpreterState_GET(void) {
> PyThreadState *tstate = _PyThreadState_GET();
> #ifdef Py_DEBUG
> _Py_EnsureTstateNotNULL(tstate);
> #endif
> # <<----------- suspect state is nullpointer
> return tstate->interp;
> }
>
> any clues , whats going on here, and how I can mitigate that ?
> --
> https://mail.python.org/mailman/listinfo/python-list

1

rocksolid light 0.9.8
clearnet tor