Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-03 Thread Dan Ciprus (dciprus) via Python-list

I'd be interested too :-).

On Thu, Sep 26, 2024 at 03:34:05AM GMT, marc nicole via Python-list wrote:

Could you show a python code example of this?


On Thu, 26 Sept 2024, 03:08 Cameron Simpson,  wrote:


On 25Sep2024 22:56, marc nicole  wrote:
>How to create a per-thread event in Python 2.7?

Every time you make a Thread, make an Event. Pass it to the thread
worker function and keep it to hand for your use outside the thread.
___
Tutor maillist  -  tu...@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


--
https://mail.python.org/mailman/listinfo/python-list


--
Dan Ciprus

[ curl -L http://git.io/unix ]


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [Tutor] How to stop a specific thread in Python 2.7?

2024-10-03 Thread Cameron Simpson via Python-list

On 03Oct2024 22:12, Dan Ciprus (dciprus)  wrote:

I'd be interested too :-).


Untested sketch:

def make_thread(target, *a, E=None, **kw):
'''
Make a new Event E and Thread T, pass `[E,*a]` as the target 
positional arguments.

A shared preexisting Event may be supplied.
Return a 2-tuple of `(T,E)`.
'''
if E is None:
  E = Event()
T = Thread(target=target, args=[E, *a], kwargs=kw)
return T, E

Something along those lines.

Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: Python crash together with threads

2024-10-03 Thread Left Right via Python-list
> 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
 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  0x7f6837fe000f in _PyInterpreterState_GET () at
> ./Include/internal/pycore_pystate.h:179
> #1  get_float_state () at Objects/floatobject.c:38
> #2  PyFloat_FromDouble (fval=3.2998) at
> Objects/floatobject.c:136
> #3  0x015a021f in python_testfunc() ()
> #4  0x01433301 in CGALWorker::work() ()
> #5  0x00457135 in CGALWorker::qt_static_metacall(QObject*,
> QMetaObject::Call, int, void**) ()
> #6  0x7f68364d0f9f in void doActivate(QObject*, int, void**) ()
> at /lib64/libQt5Core.so.5
> #7  0x7f68362e66ee in QThread::started(QThread::QPrivateSignal) () at
> /lib64/libQt5Core.so.5
> #8  0x7f68362e89c4 in QThreadPrivate::start(void*) () at
> /lib64/libQt5Core.so.5
> #9  0x7f6835cae19d in start_thread () at /lib64/libc.so.6
> #10 0x7f6835d2fc60 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
-- 
https://mail.python.org/mailman/listinfo/python-list


doRe: Help with Streaming and Chunk Processing for Large JSON Data (60 GB) from Kenna API

2024-10-03 Thread Greg Ewing via Python-list

On 3/10/24 11:48 am, Left Right wrote:

So, streaming parsers (eg. SAX) are written for a regular language
that approximates XML.


SAX doesn't parse a whole XML document, it parses small pieces of it
independently and passes them on. It's more like a lexical analyser than
a parser in that respect.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list