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

Method monitor

mininet/node.py:333–363  ·  view source on GitHub ↗

Monitor and return the output of a command. Set self.waiting to False if command has completed. timeoutms: timeout in ms or None to wait indefinitely findPid: look for PID from mnexec -p

( self, timeoutms=None, findPid=True )

Source from the content-addressed store, hash-verified

331 self.write( intr )
332
333 def monitor( self, timeoutms=None, findPid=True ):
334 """Monitor and return the output of a command.
335 Set self.waiting to False if command has completed.
336 timeoutms: timeout in ms or None to wait indefinitely
337 findPid: look for PID from mnexec -p"""
338 ready = self.waitReadable( timeoutms )
339 if not ready:
340 return ''
341 data = self.read( 1024 )
342 pidre = r'\[\d+\] \d+\r\n'
343 # Look for PID
344 marker = chr( 1 ) + r'\d+\r\n'
345 if findPid and chr( 1 ) in data:
346 # suppress the job and PID of a backgrounded command
347 if re.findall( pidre, data ):
348 data = re.sub( pidre, '', data )
349 # Marker can be read in chunks; continue until all of it is read
350 while not re.findall( marker, data ):
351 data += self.read( 1024 )
352 markers = re.findall( marker, data )
353 if markers:
354 self.lastPid = int( markers[ 0 ][ 1: ] )
355 data = re.sub( marker, '', data )
356 # Look for sentinel/EOF
357 if len( data ) > 0 and data[ -1 ] == chr( 127 ):
358 self.waiting = False
359 data = data[ :-1 ]
360 elif chr( 127 ) in data:
361 self.waiting = False
362 data = data.replace( chr( 127 ), '' )
363 return data
364
365 def waitOutput( self, verbose=False, findPid=True ):
366 """Wait for a command to complete.

Callers 4

waitOutputMethod · 0.95
waitForNodeMethod · 0.45
handleReadableMethod · 0.45
multipingFunction · 0.45

Calls 2

waitReadableMethod · 0.95
readMethod · 0.95

Tested by

no test coverage detected