Revision 31fe4f1b mininet/util.py
mininet/util.py | ||
---|---|---|
4 | 4 |
|
5 | 5 |
from time import sleep |
6 | 6 |
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE |
7 |
from select import poll, POLLIN |
|
7 |
from select import poll, POLLIN, POLLHUP
|
|
8 | 8 |
from subprocess import call, check_call, Popen, PIPE, STDOUT |
9 | 9 |
import re |
10 | 10 |
from fcntl import fcntl, F_GETFL, F_SETFL |
... | ... | |
326 | 326 |
# Use non-blocking reads |
327 | 327 |
flags = fcntl( fd, F_GETFL ) |
328 | 328 |
fcntl( fd, F_SETFL, flags | O_NONBLOCK ) |
329 |
while True:
|
|
329 |
while popens:
|
|
330 | 330 |
fds = poller.poll( timeoutms ) |
331 | 331 |
if fds: |
332 |
for fd, _event in fds:
|
|
332 |
for fd, event in fds: |
|
333 | 333 |
host = fdToHost[ fd ] |
334 | 334 |
popen = popens[ host ] |
335 |
if readline: |
|
336 |
# Attempt to read a line of output |
|
337 |
# This blocks until we receive a newline! |
|
338 |
line = popen.stdout.readline() |
|
339 |
else: |
|
340 |
line = popen.stdout.read( readmax ) |
|
341 |
yield host, line |
|
335 |
if event & POLLIN: |
|
336 |
if readline: |
|
337 |
# Attempt to read a line of output |
|
338 |
# This blocks until we receive a newline! |
|
339 |
line = popen.stdout.readline() |
|
340 |
else: |
|
341 |
line = popen.stdout.read( readmax ) |
|
342 |
yield host, line |
|
342 | 343 |
# Check for EOF |
343 |
if not line: |
|
344 |
popen.poll() |
|
345 |
if popen.returncode is not None: |
|
346 |
poller.unregister( fd ) |
|
347 |
del popens[ host ] |
|
348 |
if not popens: |
|
349 |
return |
|
344 |
elif event & POLLHUP: |
|
345 |
poller.unregister( fd ) |
|
346 |
del popens[ host ] |
|
350 | 347 |
else: |
351 | 348 |
yield None, '' |
352 | 349 |
|
Also available in: Unified diff