Revision 134a75ef mininet/util.py

View differences:

mininet/util.py
3 3
from time import sleep
4 4
from resource import setrlimit, RLIMIT_NPROC, RLIMIT_NOFILE
5 5
from select import poll, POLLIN
6
from os import read
7 6
from subprocess import call, check_call, Popen, PIPE, STDOUT
8 7
from mininet.log import output, error
8
import re
9 9

  
10 10
# Command execution support
11 11

  
......
33 33
    # We can't use Popen.communicate() because it uses
34 34
    # select(), which can't handle
35 35
    # high file descriptor numbers! poll() can, however.
36
    output = ''
36
    out = ''
37 37
    readable = poll()
38 38
    readable.register( popen.stdout )
39 39
    while True:
......
41 41
            data = popen.stdout.read( 1024 )
42 42
            if len( data ) == 0:
43 43
                break
44
            output += data
44
            out += data
45 45
        popen.poll()
46 46
        if popen.returncode != None:
47 47
            break
48
    return output
48
    return out
49 49

  
50 50
# This is a bit complicated, but it enables us to
51 51
# monitor commount output as it is happening
......
254 254
    "Fix ridiculously small resource limits."
255 255
    setrlimit( RLIMIT_NPROC, ( 4096, 8192 ) )
256 256
    setrlimit( RLIMIT_NOFILE, ( 16384, 32768 ) )
257

  
258
def natural( text ):
259
    "To sort sanely/alphabetically: sorted( l, key=natural )"
260
    def num( s ):
261
        return int( s ) if s.isdigit() else text
262
    return [  num( s ) for s in re.split( r'(\d+)', text ) ]

Also available in: Unified diff