Hi all I am doing something which works, but I have a gut feel that it cannot be relied upon. Can someone confirm this one way or the other.
I have a multi-threaded server, which responds to client logins and sets up a thread for each active session. A thread can stay active for a long time. I use a subclass of threading.Thread to handle the session, to which I have added a number of attributes and methods, plus a reference back to the main thread. When a user logs in, I call a 'setup' method in the thread, which among other things updates a dictionary in the main thread to record the fact that they are logged in. When they log out, I call a 'cleanup' method in the thread, which among other things removes their id from the dictionary of active logins. It sometimes happens that an unhandled exception occurs in a thread. The main thread continues, other threads are unaffected, and users can continue to log in. However, the user that was active at the time cannot log back in as their cleanup method was never called. There are a number of ways to handle this, but I found one which seems quite effective. In the dictionary of active logins, I store a reference to the thread which is managing the session. If the user tries to log back in, I can detect that the thread is in a suspended state, and I use the reference to invoke the thread's cleanup method. This removes the entry from the dictionary of active logins and enables the user to log in again successfully. My worry is that the thread with the unhandled exception may eventually get garbage-collected, in which case the cleanup method will no longer be accessible. Could this happen, or does the thread stay in memory until termination of the main program? Thanks for any pointers. Frank Millman -- http://mail.python.org/mailman/listinfo/python-list