gnetclisdk 1.1.0__tar.gz → 1.1.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.

Potentially problematic release.


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

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gnetclisdk
3
- Version: 1.1.0
3
+ Version: 1.1.2
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
@@ -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,10 +51,9 @@ 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
- break
55
54
  if not output:
56
- continue
55
+ logger.debug("stop waiting url, eof found")
56
+ break
57
57
  logger.debug("gnetcli output: %s", output.strip())
58
58
  try:
59
59
  data = json.loads(output)
@@ -73,13 +73,24 @@ class GnetcliStarter:
73
73
  async def __aenter__(self) -> str:
74
74
  self._proc = await self._start()
75
75
  try:
76
- return await asyncio.wait_for(
76
+ url = await asyncio.wait_for(
77
77
  self._wait_url(), timeout=self._start_timeout
78
78
  )
79
79
  except asyncio.TimeoutError:
80
80
  logger.error("gnetcli _wait_url timeout, terminating")
81
81
  await self._terminate()
82
82
  raise RuntimeError("gnetcli start failed")
83
+ logger.info("gnetcli started with url: %s", url)
84
+ self._reader_task = asyncio.create_task(self._communicate())
85
+ return url
86
+
87
+ async def _communicate(self) -> None:
88
+ while proc := self._proc:
89
+ output = await proc.stderr.readline()
90
+ if not output:
91
+ logger.debug("stop reading, eof found")
92
+ return
93
+ logger.debug("gnetcli output: %s", output.strip())
83
94
 
84
95
  async def _terminate(self) -> None:
85
96
  if (proc := self._proc) is None:
@@ -89,12 +100,17 @@ class GnetcliStarter:
89
100
  "gnetcli already terminated with code: %s", proc.returncode
90
101
  )
91
102
  return
103
+ logger.debug("terminate gnetcli")
92
104
  proc.terminate()
93
105
  try:
94
106
  await asyncio.wait_for(proc.wait(), timeout=self._stop_timeout)
95
- except TimeoutExpired:
107
+ except TimeoutError:
96
108
  logger.debug("gnetcli terminate failed, killing")
97
109
  self._proc.kill()
110
+ logger.debug("gnetcli terminated with code: %s", proc.returncode)
111
+ if self._reader_task is not None and not self._reader_task.cancel() and not self._reader_task.cancelling():
112
+ self._reader_task.cancel()
113
+ self._reader_task = None
98
114
  self._proc = None
99
115
 
100
116
  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.2
4
4
  Summary: Client for Gnetcli GRPC-server
5
5
  Home-page: https://github.com/annetutil/gnetcli
6
6
  Author: Alexander Balezin
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes