[tor-commits] [stem/master] Make exit_used.py compatible with asyncio
atagar at torproject.org
atagar at torproject.org
Thu Nov 18 22:02:33 UTC 2021
commit 7e9ea4dbb80e81d2a977937ccfca57bb41e20270
Author: Damian Johnson <atagar at torproject.org>
Date: Thu Nov 18 13:42:22 2021 -0800
Make exit_used.py compatible with asyncio
Honestly this is probably somewhat a step backward because if I return to Stem
I plan to substantially revert the asyncio migration, but for now simply fixing
the script. With the current codebase it fails with...
% python exit_used.py
Tracking requests for tor exits. Press 'enter' to end.
stem/stem/control.py:4004: RuntimeWarning: coroutine 'Controller.get_circuit' was never awaited
log.warn('Event listener raised an uncaught exception (%s): %s' % (exc, event))
---
docs/_static/example/exit_used.py | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/docs/_static/example/exit_used.py b/docs/_static/example/exit_used.py
index 296b0864..4462620e 100644
--- a/docs/_static/example/exit_used.py
+++ b/docs/_static/example/exit_used.py
@@ -17,18 +17,18 @@ def main():
input() # wait for user to press enter
-def stream_event(controller, event):
+async def stream_event(controller, event):
if event.status == StreamStatus.SUCCEEDED and event.circ_id:
- circ = controller.get_circuit(event.circ_id)
+ circ = await controller.get_circuit(event.circ_id)
exit_fingerprint = circ.path[-1][0]
- exit_relay = controller.get_network_status(exit_fingerprint)
+ exit_relay = await controller.get_network_status(exit_fingerprint)
print('Exit relay for our connection to %s' % (event.target))
print(' address: %s:%i' % (exit_relay.address, exit_relay.or_port))
print(' fingerprint: %s' % exit_relay.fingerprint)
print(' nickname: %s' % exit_relay.nickname)
- print(' locale: %s' % controller.get_info('ip-to-country/%s' % exit_relay.address, 'unknown'))
+ print(' locale: %s' % (await controller.get_info('ip-to-country/%s' % exit_relay.address), 'unknown'))
print('')
More information about the tor-commits
mailing list