[tor-dev] Raising exceptions in add_event_listener() threads (was Re: HSv3 descriptor work in stem)
Damian Johnson
atagar at torproject.org
Thu Nov 28 00:56:12 UTC 2019
Thanks George, this is a great question! I've expanded our tutorial to
hopefully cover this a bit better...
https://stem.torproject.org/tutorials/tortoise_and_the_hare.html#advanced-listeners
You can trivially print exceptions within your listener if that is all
you care about...
========================================
import time
import traceback
from stem.control import EventType, Controller
def broken_handler(event):
try:
raise ValueError('boom')
except:
print(traceback.format_exc())
with Controller.from_port() as controller:
controller.authenticate()
controller.add_event_listener(broken_handler, EventType.BW)
time.sleep(2)
========================================
% python demo.py
Traceback (most recent call last):
File "demo.py", line 9, in broken_handler
raise ValueError('boom')
ValueError: boom
Traceback (most recent call last):
File "demo.py", line 9, in broken_handler
raise ValueError('boom')
ValueError: boom
========================================
... but if your event handler has grown sophisticated enough to make
this a significant issue I'd suggest a producer/consumer model as the
tutorial now demonstrates.
Cheers! -Damian
More information about the tor-dev
mailing list