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

[tor-commits] [stem/master] Make `Controller.get_accounting_stats` asynchronous



commit d2c65fe459457fc038ec8a1281816abbacb2be9d
Author: Illia Volochii <illia.volochii@xxxxxxxxx>
Date:   Wed Apr 15 22:05:32 2020 +0300

    Make `Controller.get_accounting_stats` asynchronous
---
 stem/control.py | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index c5cbbf81..d6034fff 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1440,7 +1440,7 @@ class Controller(BaseController):
     return listeners
 
   @with_default()
-  def get_accounting_stats(self, default: Any = UNDEFINED) -> 'stem.control.AccountingStats':
+  async def get_accounting_stats(self, default: Any = UNDEFINED) -> 'stem.control.AccountingStats':
     """
     get_accounting_stats(default = UNDEFINED)
 
@@ -1457,14 +1457,16 @@ class Controller(BaseController):
       and no default was provided
     """
 
-    if self.get_info('accounting/enabled') != '1':
+    if await self.get_info('accounting/enabled') != '1':
       raise stem.ControllerError("Accounting isn't enabled")
 
     retrieved = time.time()
-    status = self.get_info('accounting/hibernating')
-    interval_end = self.get_info('accounting/interval-end')
-    used = self.get_info('accounting/bytes')
-    left = self.get_info('accounting/bytes-left')
+    status, interval_end, used, left = await asyncio.gather(
+      self.get_info('accounting/hibernating'),
+      self.get_info('accounting/interval-end'),
+      self.get_info('accounting/bytes'),
+      self.get_info('accounting/bytes-left'),
+    )
 
     interval_end = stem.util.str_tools._parse_timestamp(interval_end)
     used_read, used_written = [int(val) for val in used.split(' ', 1)]



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits