[C++-sig] Threads and boost Python

Johann Borck johann.borck at densedata.com
Mon Sep 17 20:08:16 CEST 2007


Matthew Scouten wrote:
> The (large, complex) library I am wrapping uses threads. The user make
> calls into the lib make a request,  and the lib calls back on a
> different thread some time later.
>
> I am aware that Python has some multi-threading  support, but I am not
> sure how this will interoperate with boost python. For example, are
> there any special things I need to do in the wrapper? Are there any
> common gotchas I need to know about?
>
I'd suggest you read about pythons global interpreter lock (GIL).
Threading in python is tricky and often not what one expects when
using the term "threads". Some projects use processes instead to avoid
some of the issues with python-threads. But it depends on the library
you wrap, and it is very hard to say anything general but "better be
careful when using them".

http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm
http://effbot.org/pyfaq/can-t-we-get-rid-of-the-global-interpreter-lock.htm

http://mail.python.org/pipermail/c++-sig/2007-July/012617.html
http://mail.python.org/pipermail/c++-sig/2006-January/010034.html

http://mirrors.techiesabode.com/linuxgazette/107/pai.html
http://www.thescripts.com/forum/thread23198.html

http://jessenoller.com/2007/09/12/have-gil-want-benchmarks/

http://mail.python.org/pipermail/python-dev/2003-January/032429.html



Johann




More information about the Cplusplus-sig mailing list