Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using poll instead of select in forwarder #24

Merged
merged 4 commits into from
Dec 12, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions wurlitzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,13 @@ def forwarder():
"""Forward bytes on a pipe to stream messages"""
draining = False
flush_interval = 0
poller = select.poll()
for pipe_ in pipes: poller.register(pipe_)
jayendra13 marked this conversation as resolved.
Show resolved Hide resolved

while pipes:
r, w, x = select.select(pipes, [], [], flush_interval)
if r:
events = poller.poll(flush_interval)
#r = all([(r_[1] == (select.POLLIN | select.POLLPRI)) for r_ in events])
if events:
# found something to read, don't block select until
# we run out of things to read
flush_interval = 0
Expand All @@ -194,18 +198,21 @@ def forwarder():
flush_queue.put('flush')
flush_interval = self.flush_interval
continue
for pipe in r:
if pipe == self._control_r:

for fd, flags in events:
if fd == self._control_r:
draining = True
os.close(self._control_r)
pipes.remove(self._control_r)
poller.unregister(self._control_r)
jayendra13 marked this conversation as resolved.
Show resolved Hide resolved
continue
name = names[pipe]
data = os.read(pipe, 1024)
name = names[fd]
data = os.read(fd, 1024)
if not data:
# pipe closed, stop polling it
os.close(pipe)
pipes.remove(pipe)
os.close(fd)
pipes.remove(fd)
poller.unregister(fd)
jayendra13 marked this conversation as resolved.
Show resolved Hide resolved
else:
handler = getattr(self, '_handle_%s' % name)
handler(data)
Expand Down