+5
-8
@@ -4,7 +4,7 @@ from mininet.log import output, info, error, warn
|
|||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
|
||||||
from select import poll, POLLIN
|
from select import poll, POLLIN, POLLHUP
|
||||||
from subprocess import call, check_call, Popen, PIPE, STDOUT
|
from subprocess import call, check_call, Popen, PIPE, STDOUT
|
||||||
import re
|
import re
|
||||||
from fcntl import fcntl, F_GETFL, F_SETFL
|
from fcntl import fcntl, F_GETFL, F_SETFL
|
||||||
@@ -326,12 +326,13 @@ def pmonitor(popens, timeoutms=500, readline=True,
|
|||||||
# Use non-blocking reads
|
# Use non-blocking reads
|
||||||
flags = fcntl( fd, F_GETFL )
|
flags = fcntl( fd, F_GETFL )
|
||||||
fcntl( fd, F_SETFL, flags | O_NONBLOCK )
|
fcntl( fd, F_SETFL, flags | O_NONBLOCK )
|
||||||
while True:
|
while popens:
|
||||||
fds = poller.poll( timeoutms )
|
fds = poller.poll( timeoutms )
|
||||||
if fds:
|
if fds:
|
||||||
for fd, _event in fds:
|
for fd, event in fds:
|
||||||
host = fdToHost[ fd ]
|
host = fdToHost[ fd ]
|
||||||
popen = popens[ host ]
|
popen = popens[ host ]
|
||||||
|
if event & POLLIN:
|
||||||
if readline:
|
if readline:
|
||||||
# Attempt to read a line of output
|
# Attempt to read a line of output
|
||||||
# This blocks until we receive a newline!
|
# This blocks until we receive a newline!
|
||||||
@@ -340,13 +341,9 @@ def pmonitor(popens, timeoutms=500, readline=True,
|
|||||||
line = popen.stdout.read( readmax )
|
line = popen.stdout.read( readmax )
|
||||||
yield host, line
|
yield host, line
|
||||||
# Check for EOF
|
# Check for EOF
|
||||||
if not line:
|
elif event & POLLHUP:
|
||||||
popen.poll()
|
|
||||||
if popen.returncode is not None:
|
|
||||||
poller.unregister( fd )
|
poller.unregister( fd )
|
||||||
del popens[ host ]
|
del popens[ host ]
|
||||||
if not popens:
|
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
yield None, ''
|
yield None, ''
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user