Problems with threads and embedding

  • Thread starter daniel.poelzleithner
  • Start date
D

daniel.poelzleithner

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

i wrote a module for ctrlproxy which embedds python and provides an api
that ctrlproxy is scriptable.

Every script is started in an own interpreter instance and registers
some callback functions for different events.
The module is threadsafe and everything works just fine, with one
exceptions, dead threads are not removed from the process list.



import time
import thread
import sys
import os

def runme():
time.sleep(2)
print "PID: %s" %(os.getpid())
print "PID: %s" %(os.getppid())
print " ------------ END -------------"

print thread.start_new(runme,())


Results in:


poelzi 20633 0.1 2.2 17296 11508 pts/17 S 02:24 0:12 | \_
gdb ./ctrlproxy
poelzi 15187 0.7 1.0 13136 5464 pts/17 T 05:55 0:00 |
\_ /home/poelzi/Projects/ctrlproxy/ctrlproxy
poelzi 15189 0.0 1.0 13136 5464 pts/17 T 05:55 0:00 |
~ \_ /home/poelzi/Projects/ctrlproxy/ctrlproxy
poelzi 15190 0.0 0.0 0 0 pts/17 Z 05:55 0:00 |
~ \_ [ctrlproxy] <defunct>



I tried to spend time in every created thread through the advanced
debugging api, but this changed nothing. I experimented with the
sys.exitfunc without success.


I added some debugging function to see what happens.

[...]
** INFO: Loading Python scripts
CREATED THREAD 16384
[...]

16384 is the thread of the script

[...]
ID:0:/home/poelzi/Projects/ctrlproxy/example/test.py
Joining channel #test
IS: 0x80cba58 134560928
TS: 0x810e2d0 16386
TS: 0x80fe860 16384
TS: 0x80bb028 16384
IS: 0x8083638 16384
TS: 0x8083660 16384
IS: 0x80cba58 134560928
TS: 0x810e2d0 16386
TS: 0x80fe860 16384
TS: 0x80bb028 16384
IS: 0x8083638 16384
TS: 0x8083660 16384
** INFO: ------------ END -------------
IS: 0x80cba58 134560928
TS: 0x80fe860 16384
TS: 0x80bb028 16384
IS: 0x8083638 16384
TS: 0x8083660 16384
IS: 0x80cba58 134560928
TS: 0x80fe860 16384
TS: 0x80bb028 16384
IS: 0x8083638 16384
TS: 0x8083660 16384

IS is a interpreter state and TS a thread state.
16386 seems to be the thread created by the script. After it exists,
Python knows nothing about the thread anymore, but the return code
didn't seems to be catched.


The sourcecode is to large and CVSweb currently broken...
I uploaded the code @
http://files.poelzi.org/tmp/ctrlproxy_python/

http://files.poelzi.org/tmp/ctrlproxy_python/python.c is the main file.


Any hints for me so solve this anoying problem ? :(


regards
~ Daniel

- --
nihil me cirumdat

... . .. ... . . .. . ... . .. . ... . . .
pgp key @ http://files.poelzi.org/pgp.txt
ED80 E53D 5269 4BB1 1E73 3A53 CBF9 A421 0A7B 003D
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Debian - http://enigmail.mozdev.org

iD8DBQE/+sOVy/mkIQp7AD0RAg5mAJwKD+DTxhmsQu8bzKnzSj5f/p0bjQCgp/Tf
M07tS7uaBFLKi5Z0/IjvSi4=
=doSL
-----END PGP SIGNATURE-----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top