Skip to content

Commit

Permalink
sync client: Make iteration methods more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
dvolodin7 committed Jan 30, 2024
1 parent 2c1a9cd commit 7f0dce1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/gufo/snmp/sync_client/getbulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


# Python modules
import time
from typing import List, Optional, Tuple

# Gufo Labs Modules
Expand Down Expand Up @@ -58,9 +59,13 @@ def __next__(self: "GetBulkIter") -> Tuple[str, ValueType]:
# Policer
if self._policer:
self._policer.wait_sync()
else:
# Kind of ancient dark magic to force
# a context switch and prevent EWOULDBLOCK
time.sleep(0.0)
#
try:
self.buffer = self._sock.sync_getbulk(self._ctx)
self._buffer = self._sock.sync_getbulk(self._ctx)
except BlockingIOError as e:
raise TimeoutError from e
# End
Expand Down
5 changes: 5 additions & 0 deletions src/gufo/snmp/sync_client/getnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


# Python modules
import time
from typing import Optional, Tuple

# Gufo Labs Modules
Expand Down Expand Up @@ -47,6 +48,10 @@ def __next__(self: "GetNextIter") -> Tuple[str, ValueType]:
"""Get next value."""
if self._policer:
self._policer.wait_sync()
else:
# Kind of ancient dark magic to force
# a context switch and prevent EWOULDBLOCK
time.sleep(0.0)
try:
return self._sock.sync_getnext(self._ctx)
except StopAsyncIteration as e:
Expand Down

0 comments on commit 7f0dce1

Please sign in to comment.