gnetclisdk 1.1.0__py3-none-any.whl → 1.1.1__py3-none-any.whl

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.

Potentially problematic release.


This version of gnetclisdk might be problematic. Click here for more details.

gnetclisdk/starter.py CHANGED
@@ -3,7 +3,7 @@ import json
3
3
  import logging
4
4
  from asyncio.subprocess import Process
5
5
  from json import JSONDecodeError
6
- from subprocess import DEVNULL, PIPE, TimeoutExpired
6
+ from subprocess import DEVNULL, PIPE
7
7
 
8
8
  from gnetclisdk.config import Config, LogConfig, AuthAppConfig, config_to_yaml
9
9
 
@@ -29,6 +29,7 @@ class GnetcliStarter:
29
29
  self._proc: Process | None = None
30
30
  self._start_timeout = start_timeout
31
31
  self._stop_timeout = stop_timeout
32
+ self._reader_task: asyncio.Task | None = None
32
33
 
33
34
  async def _start(self) -> Process:
34
35
  logger.debug("Starting Gnetcli server: %s", self._server_path)
@@ -50,7 +51,7 @@ class GnetcliStarter:
50
51
  async def _wait_url(self) -> str:
51
52
  while proc := self._proc:
52
53
  output = await proc.stderr.readline()
53
- if output == "" and proc.returncode is not None:
54
+ if not output and proc.returncode is not None:
54
55
  break
55
56
  if not output:
56
57
  continue
@@ -73,13 +74,26 @@ class GnetcliStarter:
73
74
  async def __aenter__(self) -> str:
74
75
  self._proc = await self._start()
75
76
  try:
76
- return await asyncio.wait_for(
77
+ url = await asyncio.wait_for(
77
78
  self._wait_url(), timeout=self._start_timeout
78
79
  )
79
80
  except asyncio.TimeoutError:
80
81
  logger.error("gnetcli _wait_url timeout, terminating")
81
82
  await self._terminate()
82
83
  raise RuntimeError("gnetcli start failed")
84
+ logger.info("gnetcli started with url: %s", url)
85
+ self._reader_task = asyncio.create_task(self._communicate())
86
+ return url
87
+
88
+ async def _communicate(self) -> None:
89
+ while proc := self._proc:
90
+ output = await proc.stderr.readline()
91
+ if not output and proc.returncode is not None:
92
+ logger.debug("stop reading, gnetcli terminated")
93
+ return
94
+ if not output:
95
+ continue
96
+ logger.debug("gnetcli output: %s", output.strip())
83
97
 
84
98
  async def _terminate(self) -> None:
85
99
  if (proc := self._proc) is None:
@@ -89,12 +103,17 @@ class GnetcliStarter:
89
103
  "gnetcli already terminated with code: %s", proc.returncode
90
104
  )
91
105
  return
106
+ logger.debug("terminate gnetcli")
92
107
  proc.terminate()
93
108
  try:
94
109
  await asyncio.wait_for(proc.wait(), timeout=self._stop_timeout)
95
- except TimeoutExpired:
110
+ except TimeoutError:
96
111
  logger.debug("gnetcli terminate failed, killing")
97
112
  self._proc.kill()
113
+ logger.debug("gnetcli terminated with code: %s", proc.returncode)
114
+ if self._reader_task is not None and not self._reader_task.cancel() and not self._reader_task.cancelling():
115
+ self._reader_task.cancel()
116
+ self._reader_task = None
98
117
  self._proc = None
99
118
 
100
119
  async def __aexit__(self, exc_type, exc_val, exc_tb):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gnetclisdk
3
- Version: 1.1.0
3
+ Version: 1.1.1
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
@@ -3,11 +3,11 @@ gnetclisdk/client.py,sha256=5LEIvHqWk2EVSw4xsaVWPOFahPAiuMObMe2bb9YStu8,19806
3
3
  gnetclisdk/config.py,sha256=8Zj9oJdZXE27fMHQy2DBdC6KXdL8flDQ2w3fgc7xXNs,1364
4
4
  gnetclisdk/exceptions.py,sha256=Cg94IdDAzQ9Q56Tdif6ladV1IcdBUg0TPa54OBVhJD0,4038
5
5
  gnetclisdk/interceptors.py,sha256=apj3l4lnR2ZcsA49odptrBC0kTDmP6Mp0EzYkeEJz9Y,7010
6
- gnetclisdk/starter.py,sha256=h3Qd6STKGfoobmxSUf2R8DdOqqd7HA4HDcTyEj0eygM,3432
6
+ gnetclisdk/starter.py,sha256=xXwCNicAT2i3gXxI91uc0GlhWbkqxa4fJwTSPeLJJWQ,4307
7
7
  gnetclisdk/proto/server_pb2.py,sha256=v_A3rRjuWKa7rPOrsAPOl_oLmfD4sqT5ELpAyM3cUI0,8126
8
8
  gnetclisdk/proto/server_pb2.pyi,sha256=66Oq_YbkGgEQt9ea-P64H58hiUZoMhqptlMQdl2IAaw,8402
9
9
  gnetclisdk/proto/server_pb2_grpc.py,sha256=H_CmevWcjvGTvp4TmzEV-TJRPq2SsQ6UgoCDc-hosyo,12805
10
- gnetclisdk-1.1.0.dist-info/METADATA,sha256=QPnFLuTdBzkK3SfYS6LbxVTQ_3bXHQYh6RdehItUUlY,1814
11
- gnetclisdk-1.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
- gnetclisdk-1.1.0.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
13
- gnetclisdk-1.1.0.dist-info/RECORD,,
10
+ gnetclisdk-1.1.1.dist-info/METADATA,sha256=FfBiCWzQbAhs0ww0KqsyguLbt_vjvoJNmY1rBGC4t18,1814
11
+ gnetclisdk-1.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
12
+ gnetclisdk-1.1.1.dist-info/top_level.txt,sha256=MNjS8LEt6d2rZ-dUbV2cnqkuTMu3EqEL2eiSvUZuUlA,11
13
+ gnetclisdk-1.1.1.dist-info/RECORD,,