[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [tor-dev] Raising exceptions in add_event_listener() threads (was Re: HSv3 descriptor work in stem)



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
_______________________________________________
tor-dev mailing list
tor-dev@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-dev