Calling PySys_WriteStdout from embedded Python

E

Eli

Hello all,
I'm embedding Python in my C application. The application makes several
calls to PySys_WriteStdout from the main thread and so far it's ok.
A problem occurs when I'm creating another thread (in Windows with
CreateThread) and trying to call PySys_WriteStdout from there; at the
first try it crashed.

I've added some locking calls and now the code looks like this (from
the thread):
PyEval_AcquireLock();
PyThreadState *interp = Py_NewInterpreter();
PyThreadState_Swap(interp);

PySys_WriteStdout("write somthing...");

PyEval_ReleaseThread(interp);
PyEval_ReleaseLock();

Well the code does not crash now, but it doesn't display anything in
Python's console. If I call PySys_WriteStdout from the main thread it
does display alright.

Any ideas how I can get PySys_WriteStdout to work within a thread?
tnanks,
Eli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,239
Messages
2,571,200
Members
47,838
Latest member
elibuskamoSeAve

Latest Threads

Top