Skip to content

Commit

Permalink
Fix control server response writes
Browse files Browse the repository at this point in the history
  • Loading branch information
daniil-berg committed May 8, 2022
1 parent ee0b8c0 commit 051d0cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
author = 'Daniil Fajnberg'

# The full version, including alpha/beta/rc tags
release = '1.1.3'
release = '1.1.4'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = asyncio-taskpool
version = 1.1.3
version = 1.1.4
author = Daniil Fajnberg
author_email = [email protected]
description = Dynamically manage pools of asyncio tasks
Expand Down
12 changes: 5 additions & 7 deletions src/asyncio_taskpool/control/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ async def _exec_method_and_respond(self, method: Callable, **kwargs) -> None:
elif param.kind == param.VAR_POSITIONAL:
var_pos = kwargs.pop(param.name)
output = await return_or_exception(method, *normal_pos, *var_pos, **kwargs)
self._writer.write(CMD_OK if output is None else str(output).encode())
self._response_buffer.write(CMD_OK.decode() if output is None else str(output))

async def _exec_property_and_respond(self, prop: property, **kwargs) -> None:
"""
Expand All @@ -122,10 +122,10 @@ async def _exec_property_and_respond(self, prop: property, **kwargs) -> None:
if kwargs:
log.debug("%s sets %s.%s", self._client_class_name, self._pool.__class__.__name__, prop.fset.__name__)
await return_or_exception(prop.fset, self._pool, **kwargs)
self._writer.write(CMD_OK)
self._response_buffer.write(CMD_OK.decode())
else:
log.debug("%s gets %s.%s", self._client_class_name, self._pool.__class__.__name__, prop.fget.__name__)
self._writer.write(str(await return_or_exception(prop.fget, self._pool)).encode())
self._response_buffer.write(str(await return_or_exception(prop.fget, self._pool)))

async def client_handshake(self) -> None:
"""
Expand All @@ -147,8 +147,7 @@ async def client_handshake(self) -> None:
self._parser.add_subparsers(title="Commands",
metavar="(A command followed by '-h' or '--help' will show command-specific help.)")
self._parser.add_class_commands(self._pool.__class__)
self._writer.write(str(self._pool).encode())
self._writer.write(b'\n')
self._writer.write(str(self._pool).encode() + b'\n')
await self._writer.drain()

async def _parse_command(self, msg: str) -> None:
Expand Down Expand Up @@ -194,9 +193,8 @@ async def listen(self) -> None:
log.debug("%s disconnected", self._client_class_name)
break
await self._parse_command(msg)
response = self._response_buffer.getvalue()
response = self._response_buffer.getvalue() + "\n"
self._response_buffer.seek(0)
self._response_buffer.truncate()
self._writer.write(response.encode())
self._writer.write(b'\n')
await self._writer.drain()

0 comments on commit 051d0cb

Please sign in to comment.