Skip to content

Commit

Permalink
Yield the thread before returning from view loop
Browse files Browse the repository at this point in the history
The inner loop trying to read the multi-stream-sink-view was hogging the
GIL. This resulted in the thread that was reading from the socket not
getting scheduled often enough, which lead to timeout errors on tests
that relied on data actually being read.
  • Loading branch information
nisanharamati authored and jtfmumm committed Jun 19, 2019
1 parent e4df828 commit 13e2cbc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
16 changes: 9 additions & 7 deletions testing/tools/integration/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,20 +143,22 @@ def run(self):
view = self.sink.view(blocking=False)
msgs = 0
while not self.stopped():
if not self.values:
self.stop()
logging.debug("SinkAwait complete with remaining values: {}"
.format(self.values))
break
msg = next(view)
processed = self.func(msg) if msg is not None else None
if processed:
if msg is not None:
msgs += 1
processed = self.func(msg)
if processed in self.values:
self.values.discard(processed)
logging.debug("{} matched on value {!r}."
.format(self.name,
processed))
if not self.values:
self.stop()
logging.debug("SinkAwait complete with remaining values: {}"
.format(self.values))
break
else:
time.sleep(0.001)
if time.time() - started > self.timeout:
self.error = TimeoutError('{}: has timed out after {} seconds'
', with {} messages. before '
Expand Down
1 change: 1 addition & 0 deletions testing/tools/integration/end_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def __next__(self):
# sleep after a full round on all keys produces no value
time.sleep(0.001)
else:
time.sleep(0.001)
return None
# implicit: continue

Expand Down

0 comments on commit 13e2cbc

Please sign in to comment.