gnetcli-adapter 2.5.1__tar.gz → 2.5.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gnetcli_adapter
3
- Version: 2.5.1
3
+ Version: 2.5.2
4
4
  Summary: Gnetcli-server adapter for Annet
5
5
  Author-email: Aleksandr Balezin <gescheit12@gmail.com>
6
6
  Requires-Python: >=3.10
@@ -143,22 +143,24 @@ def check_gnetcli_server(server_path: str, config: str = DEFAULT_GNETCLI_SERVER_
143
143
 
144
144
  def cleanup():
145
145
  if _local_gnetcli_p is not None:
146
+ _local_gnetcli_p.terminate()
147
+ time.sleep(0.05)
146
148
  _local_gnetcli_p.kill()
147
-
149
+ time.sleep(0.05)
148
150
 
149
151
  atexit.register(cleanup)
150
152
 
151
153
 
152
154
  async def gather_with_concurrency(n: int, *coros: list[asyncio.Task]):
153
155
  if n == 0:
154
- return await asyncio.gather(*coros)
156
+ return await asyncio.gather(*coros, return_exceptions=True)
155
157
  semaphore = asyncio.Semaphore(n)
156
158
 
157
159
  async def sem_coro(coro):
158
160
  async with semaphore:
159
161
  return await coro
160
162
 
161
- return await asyncio.gather(*(sem_coro(c) for c in coros))
163
+ return await asyncio.gather(*(sem_coro(c) for c in coros), return_exceptions=True)
162
164
 
163
165
 
164
166
  def get_device_ip(dev: Device) -> Optional[str]:
@@ -280,24 +282,28 @@ class GnetcliFetcher(Fetcher, AdapterWithConfig, AdapterWithName):
280
282
  if files_to_download or device.is_pc():
281
283
  if files_to_download:
282
284
  files = files_to_download.get(device, [])
283
- task = asyncio.create_task(self.adownload_dev(device=device, files=files))
285
+ task = self.adownload_dev(device=device, files=files)
284
286
  tasks[task] = device
285
287
  else:
286
288
  running[device] = {}
287
289
  else:
288
- task = asyncio.create_task(self.afetch_dev(device=device))
290
+ task = self.afetch_dev(device=device)
289
291
  tasks[task] = device
290
292
 
291
293
  if not tasks:
292
294
  return running, failed_running
293
295
 
294
- done, pending = await asyncio.wait(list(tasks), return_when=asyncio.ALL_COMPLETED)
295
- for task in done:
296
- device = tasks[task]
297
- if (exc := task.exception()) is not None:
298
- failed_running[device] = exc
296
+ rtasks_dev = []
297
+ rtasks = []
298
+ for task, dev in tasks.items():
299
+ rtasks.append(task)
300
+ rtasks_dev.append(dev)
301
+ result = await gather_with_concurrency(max_slots, *rtasks)
302
+ for device, dev_res in zip(rtasks_dev, result):
303
+ if isinstance(dev_res, Exception):
304
+ failed_running[device] = dev_res
299
305
  else:
300
- running[device] = task.result()
306
+ running[device] = dev_res
301
307
  return running, failed_running
302
308
 
303
309
  async def afetch_dev(self, device: Device) -> str:
File without changes