2121
2222from reportportal_client .aio .tasks import BlockingOperationError , Task
2323
24- _T = TypeVar ('_T' )
24+ _T = TypeVar ("_T" )
2525
2626DEFAULT_TASK_TRIGGER_NUM : int = 10
2727DEFAULT_TASK_TRIGGER_INTERVAL : float = 1.0
@@ -33,11 +33,11 @@ class BatchedTask(Generic[_T], Task[_T]):
3333 __loop : asyncio .AbstractEventLoop
3434
3535 def __init__ (
36- self ,
37- coro : Union [Generator [Future , None , _T ], Awaitable [_T ]],
38- * ,
39- loop : asyncio .AbstractEventLoop ,
40- name : Optional [str ] = None
36+ self ,
37+ coro : Union [Generator [Future , None , _T ], Awaitable [_T ]],
38+ * ,
39+ loop : asyncio .AbstractEventLoop ,
40+ name : Optional [str ] = None ,
4141 ) -> None :
4242 """Initialize an instance of the Task.
4343
@@ -65,12 +65,12 @@ class ThreadedTask(Generic[_T], Task[_T]):
6565 __wait_timeout : float
6666
6767 def __init__ (
68- self ,
69- coro : Union [Generator [Future , None , _T ], Awaitable [_T ]],
70- wait_timeout : float ,
71- * ,
72- loop : asyncio .AbstractEventLoop ,
73- name : Optional [str ] = None
68+ self ,
69+ coro : Union [Generator [Future , None , _T ], Awaitable [_T ]],
70+ wait_timeout : float ,
71+ * ,
72+ loop : asyncio .AbstractEventLoop ,
73+ name : Optional [str ] = None ,
7474 ) -> None :
7575 """Initialize an instance of the Task.
7676
@@ -90,24 +90,21 @@ def blocking_result(self) -> _T:
9090 if self .done ():
9191 return self .result ()
9292 if not self .__loop .is_running () or self .__loop .is_closed ():
93- raise BlockingOperationError (' Running loop is not alive' )
93+ raise BlockingOperationError (" Running loop is not alive" )
9494 start_time = time .time ()
9595 sleep_time = sys .getswitchinterval ()
9696 while not self .done () and time .time () - start_time < self .__wait_timeout :
9797 time .sleep (sleep_time )
9898 if not self .done ():
99- raise BlockingOperationError (' Timed out waiting for the task execution' )
99+ raise BlockingOperationError (" Timed out waiting for the task execution" )
100100 return self .result ()
101101
102102
103103class BatchedTaskFactory :
104104 """Factory protocol which creates Batched Tasks."""
105105
106106 def __call__ (
107- self ,
108- loop : asyncio .AbstractEventLoop ,
109- factory : Union [Coroutine [Any , Any , _T ], Generator [Any , None , _T ]],
110- ** _
107+ self , loop : asyncio .AbstractEventLoop , factory : Union [Coroutine [Any , Any , _T ], Generator [Any , None , _T ]], ** _
111108 ) -> Task [_T ]:
112109 """Create Batched Task in appropriate Event Loop.
113110
@@ -130,10 +127,7 @@ def __init__(self, wait_timeout: float):
130127 self .__wait_timeout = wait_timeout
131128
132129 def __call__ (
133- self ,
134- loop : asyncio .AbstractEventLoop ,
135- factory : Union [Coroutine [Any , Any , _T ], Generator [Any , None , _T ]],
136- ** _
130+ self , loop : asyncio .AbstractEventLoop , factory : Union [Coroutine [Any , Any , _T ], Generator [Any , None , _T ]], ** _
137131 ) -> Task [_T ]:
138132 """Create Threaded Task in appropriate Event Loop.
139133
@@ -151,9 +145,9 @@ class TriggerTaskBatcher(Generic[_T]):
151145 __trigger_num : int
152146 __trigger_interval : float
153147
154- def __init__ (self ,
155- trigger_num : int = DEFAULT_TASK_TRIGGER_NUM ,
156- trigger_interval : float = DEFAULT_TASK_TRIGGER_INTERVAL ) -> None :
148+ def __init__ (
149+ self , trigger_num : int = DEFAULT_TASK_TRIGGER_NUM , trigger_interval : float = DEFAULT_TASK_TRIGGER_INTERVAL
150+ ) -> None :
157151 """Initialize an instance of the Batcher.
158152
159153 :param trigger_num: object number threshold which triggers batch return and reset
@@ -169,8 +163,7 @@ def __ready_to_run(self) -> bool:
169163 last_time = self .__last_run_time
170164 if len (self .__task_list ) <= 0 :
171165 return False
172- if (len (self .__task_list ) >= self .__trigger_num
173- or current_time - last_time >= self .__trigger_interval ):
166+ if len (self .__task_list ) >= self .__trigger_num or current_time - last_time >= self .__trigger_interval :
174167 self .__last_run_time = current_time
175168 return True
176169 return False
@@ -213,7 +206,7 @@ def __remove_finished(self):
213206 if not task .done ():
214207 break
215208 i += 1
216- self .__task_list = self .__task_list [i + 1 :]
209+ self .__task_list = self .__task_list [i + 1 :]
217210
218211 def append (self , value : _T ) -> None :
219212 """Add an object to internal batch.
0 commit comments