c thread routines from python

Arvind Mani marvind at Glue.umd.edu
Wed Feb 28 17:43:22 CET 2001


hi,

I have a multi-threaded C program that I need to interface with a
Tkinter
GUI. I used Swig to create a module containing all the thread routines.
Then I created
a thread in python corresponding to each thread in the C program, and
called the C
routines in them.

The problem is the that the python interpreter executes these
instructions
sequentially. I will include a small test program to illustrate my
problem.
The problem is the that the python interpreter executes these
instructions
sequentially. I will include a small test program to illustrate my
problem.

I added the code posted by Mark in the interface file but I think I got
something messed up. I would be really grateful for any help.

Thanks,
arvind

hello.c
-----
void print_hello1(void)
{
...... inf loop
}

void print_hello2(void)
{
.....inf loop
}

.i file
----

%typemap (python, except) void {
        PY_BEGIN_ALLOW_THREADS
        $function
        PY_END_ALLOW_THREADS
}

extern void print_hello1(void);
extern void print_hello2(void);

.py
---

thread.start_new_thread(hello.print_hello1, ())
thread.start_new_thread(hello.print_hello2, ())






More information about the Python-list mailing list