# 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(): |
40 | 40 | pass |
41 | 41 | |
42 | 42 | 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()) |
44 | 46 | if n > 0: |
45 | 47 | return n |
46 | | except ValueError: |
| 48 | except (ValueError, OSError): |
47 | 49 | pass |
48 | 50 | |
49 | 51 | return 1 |
… |
… |
def parse_jobs_from_MAKE(MAKE, unlimited |
84 | 86 | |
85 | 87 | # Next, find the value of -l |
86 | 88 | # 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) |
88 | 90 | if num < 1: |
89 | 91 | # No replacement done, i.e. no -l option found |
90 | 92 | pass |