timers in threaded application

Skip Montanaro skip.montanaro at gmail.com
Thu Jan 12 07:12:00 EST 2017


I know signals and threads are a bad mix, but I only discovered I was
playing with fire a few minutes ago. I've been using the websocket-client
library (https://pypi.python.org/pypi/websocket-client/) to interact with
another system at work. It implements its own event loop, but doesn't seem
to play nice with others. I used gtk/gobject for years. It implemented
timeouts for you, you could integrate it with other event loops, etc.

As far as I could tell, websocket-client implements none of that. I needed
some timer functionality, so not thinking about it too carefully, I
implemented it using signal.alarm. This worked pretty well, but I was
experiencing mysterious hangs. This morning, looking through the
websocket-client code to see if I'd missed something, I saw that it uses
threads. So, that might be my problem.

I still need timers, and for the moment I'm stuck with this package's event
loop. What options do I have? I'm certainly willing to switch to another
websocket client library if that will make all my problems go away. This is
my first ws experience though, and I inherited some code which used
websocket-client, so just went with what I had.

Thx,

Skip



More information about the Python-list mailing list