[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyKDE] embedding PyQt in a c++ app
From: Nicolas Decoster <my_name () my_company ! fr>
Date: 2004-07-30 16:23:22
Message-ID: 20040730182322.A7507 () cumbaya ! noveltis ! fr
[Download RAW message or body]
Hi.
On Thu, Jul 29, 2004 at 05:21:25PM +0200, Christoph Wiedemann wrote:
> Hello,
>
> i have problems to embed PyQt in a c++ application. Since the application
> uses threads and multiple python interpreters, i must ensure that the
> correct thread state is set and the GIL is locked, whenever the python API
> is used. I do that with the
>
> PyEval_RestoreThread(threadState);
>
> and
>
> PyEval_SaveThread();
>
> methods. This works fine, as long as i don't use widgets created with PyQt,
> because there are many "callbacks" (virtual methods), e.g. mousePressEvent,
> which are called directly from PyQt.
>
I had the same problem. But since this wasn't a major issue for my
project, I gave up without investigating. But I am interested in the
solution.
> Is there any way to force PyQt to acquire the GIL before those virtual
> methods are called?
>
> Hmm, this wouldn't solve the issue with multiple interpreters; each
> interpreter has its own thread state, which must be restored before using
> the API.
I do it something like that:
PyThreadState* _pyThreadState;
_pyThreadState = Py_NewInterpreter();
then later
PyEval_AcquireLock();
PyThreadState_Swap(_pyThreadState);
... some python stuff ...
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
and when I'm done
PyEval_AcquireLock();
PyThreadState_Swap(_pyThreadState);
Py_EndInterpreter(_pyThreadState);
PyThreadState_Swap(NULL);
PyEval_ReleaseLock();
Nicolas.
--
Nicolas Decoster
Noveltis - Parc Technologique du Canal
2, avenue de l'Europe - 31526 Ramonville Saint Agne Cedex - France
Tél. : 00 (33) 5 62 88 11 16 - Fax : 00 (33) 5 62 88 11 12
_______________________________________________
PyKDE mailing list PyKDE@mats.imk.fraunhofer.de
http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic