Skip to content

Commit

Permalink
No key-error after time-out
Browse files Browse the repository at this point in the history
  • Loading branch information
joente committed Dec 12, 2022
1 parent fbae7b7 commit 95ed585
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
12 changes: 8 additions & 4 deletions aiowmi/protocol.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import asyncio
import struct
from typing import Optional, Callable
from typing import Optional, Callable, Dict
from .dcom import Dcom
from .rpc.common import RpcCommon
from .rpc.response import RpcResponse
Expand All @@ -21,7 +21,7 @@ def __init__(self, loop: Optional[asyncio.AbstractEventLoop] = None):
self._transport = None
self._buf = None
self._tmp = b''
self._requests = {}
self._requests: Dict[int, Request] = {}
self._dcom = Dcom()

# The properties below will be set by connection.py
Expand Down Expand Up @@ -85,7 +85,11 @@ def data_received(self, data: bytes) -> None:
if more is False:
return None

req, data, = self._requests[self._buf.call_id], self._buf.data
req, data, = self._requests.get(self._buf.call_id), self._buf.data
if req is None:
if more:
self.data_received(more)
return

self._buf = None

Expand Down Expand Up @@ -184,6 +188,6 @@ async def get_dcom_response(
response.throw()

finally:
self._requests.pop(call_id)
self._requests.pop(call_id).done()

return response
5 changes: 5 additions & 0 deletions aiowmi/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ def __init__(self, size: Optional[int] = None):
self.size = size
self.fut = asyncio.Future()

def done(self):
if self.fut is not None:
self.fut.cancel()
self.fut = None

async def readn(self, n: int, timeout: int = 5) -> bytes:
assert self.fut is None

Expand Down
2 changes: 1 addition & 1 deletion aiowmi/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.2'
__version__ = '0.2.3'
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""setup.py
locan installation: pip install -e .
python setup.py sdist
twine upload --repository pypitest dist/aiowmi-x.x.x.tar.gz
twine upload --repository pypi dist/aiowmi-x.x.x.tar.gz
Expand Down

0 comments on commit 95ed585

Please sign in to comment.