Signal and thread problems on Solaris revisited -HELP!!
Alwyn Schoeman
alwyns at prism.co.za
Sat Feb 2 14:31:59 EST 2002
Hi there,
Awhile back I posted a message about having problems with signal handling
in a multithreaded application running on Solaris. I'd like to follow up
on that problem.
I've seen on the sourceforge forum's that the bug is supposedly fixed in
Python 2.2. I've thus upgraded a Solaris 8 and Solaris 7 machine to Python
2.2. Both were compiled with --with-signal-module and --with-threads.
The differences between the 2 systems are the following:
1) The one machine is Solaris 8 and the other Solaris 7.
2) The Solaris 8 Python 2.2 was compiled with gcc.
3) The Solaris 7 Python 2.2 was compiled with Sun Forte C++ 6.
I have 2 versions of my program. The one uses no implicit signal handling
but only except KeyboardInterrupt, the other uses signal handling.
On Solaris 7 machine the signal handling work perfect for both versions.
On Solaris 8 none of them work.
On request this is a pseudo description of how the program works.
The system opens 2 socket connections to 2 different external services.
Each of these 2 connections has a reader and writer thread associated with
it that consumes and produces data asynchronously. Each connection also
has a management thread associated with it which is responsable for
managing the connection state among other things. One of these connections
also has a number of processor threads responsable for processing data.
Queues are used for data access synchronization. Condition objects are
used to send messages between threads. Except for this there is also the
main thread.
I'm not going to go into the KeyboardInterrupt version as that
implementation is obvious and only differs in the main program/thread.
Main program/thread (unnecessary info excluded):
import signal
exitFlag = 0
def handler(signum,frame):
global exitFlag
if signum == 2:
exitFlag = 1
def main():
Create Manager1 thread and start.
Create Manager2 thread and start
while not exitFlag:
signal.pause()
Call setExitFlag method on Manager1.
Join on Manager1
Call setExitFlag method on Manager2
Join on Manager2
Above is the main program. The manager threads work in a similar fashion.
They initialize the threads. Enter a processing loop or idling loop, which
exits on a private exitflag that is set in the setExitFlag method of the
manager thread. The manager threads then call the setExitFlag methods of
all created workerthreads which in turn causes a private exitflag to be set
in each thread, causing the threads to exit their respective processing
loops. These threads then join in the respective Manager thread. Lastly
the Manager threads join in the main thread.
E.g. (Still pseudo pseudo)
class Manager(threading.Thread):
def __init__(self,etc):
set private exitFlag = 0
set other stuff
Call threading.Thread constructor
def setExitFlag(self):
self.__exitFlag = 1
def run(self):
create and start worker threads
while not self.__exitFlag:
do something to pass the time.
call setExitFlag method on all worker threads.
join on each thread.
Above is the basic Manager thread.
Worker threads are similar except they do not create of join other threads.
If you need more information just let me know.
On Solaris 8 I just see ^C on the console but the signal gets ignored. On 7
it works find...
I can send the output of truss in both cases, I just do not have fast
enough access now (One machine is in Manila, other in Johannesburg).
Jason Lowe's code was put into thread_pthread I think. I'm just not sure
if perhaps thread_solaris isn't used. (Shot in the dark).
Just let me know what you need....
Regards,
Alwyn Schoeman
More information about the Python-list
mailing list