[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Threading in python?

From: Ilia Mirkin
Subject: Re: [Discuss-gnuradio] Threading in python?
Date: Thu, 15 Jun 2006 00:35:50 -0400
User-agent: Internet Messaging Program (IMP) H3 (4.0.3)

Quoting Michael Ford <address@hidden>:

Up until now, all of my networking projects have been in C/C++, and I'd like
to think that I'm pretty good with threading in those languages. As with the
previous projects, I feel like threading will be a must. It's true that with
wireless nodes, I won't be sending/receiving simultaneously with the same
node. I figure that I'll have the node receiving unless the user inputs a
file to be sent, so I'll need a thread that does nothing but receive (and
that sendswhen it needs to), and a thread that constantly looks for user
input. Should I be implementing the threading on the python level, or can I
get away with doing this as a C++ file?

-Michael Ford-

A somewhat more generic answer than Eric's:

Python and threads don't mix easily. There's one python interpreter/state, and
if it's interpreting in one thread, and you try to get it to do something else
from another thread, things will go bad (trying to access state, running
functions, etc may all do Bad Things (tm)). Python 2.4 and up has the concept
of a GIL (Global Interpreter Lock), which you must acquire before doing
anything else with the interpreter in a thread context. Alternatively you can
dedicate one thread to synchronize access to the python interpreter. To my
knowledge neither SWIG nor Boost.Python are aware of the GIL, so you must
acquire/release it for them.

Additionally, python does user threads (cooperative), though they are probably
not what you're looking for.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]