gnetcli-adapter 2.5.0__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.0
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]:
@@ -168,6 +170,16 @@ def get_device_ip(dev: Device) -> Optional[str]:
168
170
  for iface in dev.interfaces:
169
171
  for ip in iface.ip_addresses:
170
172
  return ip.address.split("/")[0]
173
+ else:
174
+ try:
175
+ if dev.primary_ip:
176
+ return dev.primary_ip.address.split("/")[0]
177
+ if dev.interfaces:
178
+ for iface in dev.interfaces:
179
+ for ip in iface.ip_addresses:
180
+ return ip.address.split("/")[0]
181
+ except Exception as e:
182
+ _logger.warning("get device ip error: %s", e)
171
183
  return None
172
184
 
173
185
 
@@ -270,24 +282,28 @@ class GnetcliFetcher(Fetcher, AdapterWithConfig, AdapterWithName):
270
282
  if files_to_download or device.is_pc():
271
283
  if files_to_download:
272
284
  files = files_to_download.get(device, [])
273
- task = asyncio.create_task(self.adownload_dev(device=device, files=files))
285
+ task = self.adownload_dev(device=device, files=files)
274
286
  tasks[task] = device
275
287
  else:
276
288
  running[device] = {}
277
289
  else:
278
- task = asyncio.create_task(self.afetch_dev(device=device))
290
+ task = self.afetch_dev(device=device)
279
291
  tasks[task] = device
280
292
 
281
293
  if not tasks:
282
294
  return running, failed_running
283
295
 
284
- done, pending = await asyncio.wait(list(tasks), return_when=asyncio.ALL_COMPLETED)
285
- for task in done:
286
- device = tasks[task]
287
- if (exc := task.exception()) is not None:
288
- 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
289
305
  else:
290
- running[device] = task.result()
306
+ running[device] = dev_res
291
307
  return running, failed_running
292
308
 
293
309
  async def afetch_dev(self, device: Device) -> str:
File without changes