MCPcopy Create free account
hub / github.com/mininet/mininet / pmonitor

Function pmonitor

mininet/util.py:455–496  ·  view source on GitHub ↗

Monitor dict of hosts to popen objects a line at a time timeoutms: timeout for poll() readline: return single line of output yields: host, line/output (if any) terminates: when all EOFs received

(popens, timeoutms=500, readline=True,
             readmax=1024 )

Source from the content-addressed store, hash-verified

453# Popen support
454
455def pmonitor(popens, timeoutms=500, readline=True,
456 readmax=1024 ):
457 """Monitor dict of hosts to popen objects
458 a line at a time
459 timeoutms: timeout for poll()
460 readline: return single line of output
461 yields: host, line/output (if any)
462 terminates: when all EOFs received"""
463 poller = poll()
464 fdToHost = {}
465 fdToDecoder = {}
466 for host, popen in popens.items():
467 fd = popen.stdout.fileno()
468 fdToHost[ fd ] = host
469 fdToDecoder[ fd ] = getincrementaldecoder()
470 poller.register( fd, POLLIN )
471 flags = fcntl( fd, F_GETFL )
472 fcntl( fd, F_SETFL, flags | O_NONBLOCK )
473 # pylint: disable=too-many-nested-blocks
474 while popens:
475 fds = poller.poll( timeoutms )
476 if fds:
477 for fd, event in fds:
478 host = fdToHost[ fd ]
479 decoder = fdToDecoder[ fd ]
480 popen = popens[ host ]
481 if event & ( POLLIN | POLLHUP ):
482 while True:
483 try:
484 f = popen.stdout
485 line = decoder.decode( f.readline() if readline
486 else f.read( readmax ) )
487 except IOError:
488 line = ''
489 if line == '':
490 break
491 yield host, line
492 if event & POLLHUP:
493 poller.unregister( fd )
494 del popens[ host ]
495 else:
496 yield None, ''
497
498# Other stuff we use
499def sysctlTestAndSet( name, limit ):

Callers 2

pmonitorTestFunction · 0.90
monitorhostsFunction · 0.90

Calls 5

getincrementaldecoderFunction · 0.85
decodeMethod · 0.80
readlineMethod · 0.80
readMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected