Problems with Threads

Alexandre Perrin payou at free.fr
Fri Aug 10 10:11:55 CEST 2001


Hello,

I had the same problem recently... In fact, it mainly depends on the kind of
thread you are using.
I'm using Windows and I know that Win32 threads are incompatible with Python
(because the Python API is single-threaded), but I heard that POSIX threads
work fine.

Anyway, there is a solution to your problem. Instead of creating your thread
in C, you can create a Python thread BEFORE calling your C function. This
works fine because Python threads are safe.

Payou.

PS: I also noticed that the different interpreter (Python Idle and
Pythonwin) are using threads differently...

"Aahz Maruch" <aahz at panix.com> a écrit dans le message news:
9kv0fi$ft4$1 at panix2.panix.com...
> In article <mailman.997216332.2935.python-list at python.org>,
> superfix <superfix at bol.com.br> wrote:
> >
> >Hello guys. I have been some problems with threads in
> >python/c. Let me try explanation this:
> > - I have an interface write in python for c
> > - In this interface I call a module write in c
> > - In this module I call glutmainloop, otherwise,
> >the program enters in loop to refresh the opengl
> >aplication.
> >
> >So, I need to return to python interpreter. otherwise, I need to keep
> >two aplications in my program: python window and opengl window. Note: I
> >need to keep the terminal active together opengl.
> >
> > /*Api*/
> > include <module.c>
> > . . . . . . .
> > static PyObject *agg_CreatAgent(PyObject *self, PyObject *args)
> > {
> > int x;
> >    if (!PyArg_ParseTuple(args, "i", &x)
> > return NULL;
> >
> > Py_BEGIN_ALLOW_THREADS
> > open_function(x, "filename");
> >  Py_END_ALLOW_THREADS
> >
> > Py_INCREF(Py_None);
> >    return Py_None;
> > }
> >
> >Effect. Python simply call the open_function and fall in loop. How I
> >can return the control to the python and keep this thread active?  Any
> >thoughts?
>
> What's this thread supposed to do?  It sounds to me like you need to
> clarify your application logic.
> --
>                       --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)
>
> Hugs and backrubs -- I break Rule 6
http://www.rahul.net/aahz/
> Androgynous poly kinky vanilla queer het Pythonista
>
> "i-write-best-when-the-audience-is-me-ly y'rs  - tim"
>





More information about the Python-list mailing list