Ticket #12016: trac_12016-scripts-ref.patch

File trac_12016-scripts-ref.patch, 1.3 KB (added by jhpalmieri, 10 years ago)

scripts repo

  • sage-num-threads.py

    # HG changeset patch
    # User J. H. Palmieri <palmieri@math.washington.edu>
    # Date 1323556413 28800
    # Node ID 86cd7509c587ebfb4c76ce2820106a4ae55bd304
    # Parent  07cca33efdf7cb5207758ee695fd2199a42eae6f
    12016: use subprocess instead of popen in sage-num-threads
    
    diff --git a/sage-num-threads.py b/sage-num-threads.py
    a b def number_of_cores(): 
    4040        pass
    4141
    4242    try:  # Solaris fix
    43         n = int(os.popen2("sysctl -n hw.ncpu")[1].read().strip())
     43        from subprocess import Popen, PIPE
     44        p = Popen(['sysctl','-n','hw.ncpu'], stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
     45        n = int(p.stdout.read().strip())
    4446        if n > 0:
    4547            return n
    46     except ValueError:
     48    except (ValueError, OSError):
    4749        pass
    4850
    4951    return 1
    def parse_jobs_from_MAKE(MAKE, unlimited 
    8486
    8587    # Next, find the value of -l
    8688    # If it is specified, use this as an upper bound on j
    87     (l,num) = re.subn(r'^(.* )?(-l *|--load-average(=(?=[0-9])| +))([0-9.]*)( .*?)?$', r'\4', MAKE, count=1)
     89    (l,num) = re.subn(r'^(.* )?(-l *|--(load-average|max-load)(=(?=[0-9])| +))([0-9.]*)( .*?)?$', r'\5', MAKE, count=1)
    8890    if num < 1:
    8991        # No replacement done, i.e. no -l option found
    9092        pass