[C++-sig] FW: Converting from SWIG to Boost.Python
BHELLA,OPINDERJIT (HP-Vancouver,ex1)
opinderjit.bhella at hp.com
Fri Jan 31 02:02:52 CET 2003
In the example below, every function is wrapped with in a
Py_BEGIN_ALLOW_THREADS/
Py_END_ALLOW_THREADS macro. This macro allows each function to be able to
run in
multiple threads in Python. Because Py_END_ALLOW_THREADS must be called to
acquire the interpreter lock when the function is completed,
the PyEval_RestoreThread(_save); is also called before each catch, if an
excepting occurs
and we return NULL.
Thanks for your help David!
"BHELLA,OPINDERJIT (HP-Vancouver,ex1)" < opinderjit.bhella at hp.com
<mailto:opinderjit.bhella at hp.com>> writes:
I have read through the tutorial and was unable
> to figure out how to reproduce the
> following SWIG logic that uses the Py_BEGIN_ALLOW_THREADS and
> Py_END_ALLOW_THREADS macros.
>
<snip>
Can you explain what it does?
--
David Abrahams
dave at boost-consulting.com <mailto:dave at boost-consulting.com> *
<http://www.boost-consulting.com>
Boost support, enhancements, training, and commercial distribution
-----Original Message-----
> From: BHELLA,OPINDERJIT (HP-Vancouver,ex1)
> Sent: Thursday, January 30, 2003 11:52 AM
> To: 'c++-sig at python.org'
> Subject: Converting from SWIG to Boost.Python
>
>
> Hi,
>
> I have been using SWIG 1.5p for about a year with good success. However, I
> was interested in the newer functionality
> that Boost.Python provides. I have read through the tutorial and was
> unable to figure out how to reproduce the
> following SWIG logic that uses the Py_BEGIN_ALLOW_THREADS and
> Py_END_ALLOW_THREADS macros.
>
> Thanks.
>
> SWIG example:
> %except(python)
> {
> Py_BEGIN_ALLOW_THREADS
> try
> {
> $function
> }
> catch(BlackstoneErrorObject &e)
> {
> PyEval_RestoreThread(_save);
> switch(e.getCode())
> {
> case SUCCESS: ... break;
> case GENERAL_ERROR: break;
> default: ...break;
> }
> return NULL;
> }
> catch (...)
> {
> PyEval_RestoreThread(_save);
> PyErr_SetString(BlackstoneError,"...");
> return NULL;
> }
> Py_END_ALLOW_THREADS
> }
More information about the Cplusplus-sig
mailing list