- Exporting needed function for future reuse
- Idiomatic python: using with file as f instead of try/finally
- Fixing some indentation issues
- No need to reinvent python multiprocessing.getCPUCount()
- Removing a function parameter which is always the same under all invocations
- Adding some docstrings
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
This is great as long as multiprocessing.cpu_count() preserves the behavior we want. Does it?
Also, please make sure to add @NoQ to static analyzer reviews!
utils/analyzer/SATestBuild.py | ||
---|---|---|
133 ↗ | (On Diff #116296) | Seems reasonable and a nice clean up. Does it work on Windows, Linux, and macOS? The documentation says it is allowed to not be implemented. |
Comment Actions
Does it work on Windows, Linux, and macOS?
It definitely works on OS X and Unix.
It's Windows implementation is the same one we have, so it is not worse (apparently it can fail on some obscure Windows versions, but so can the current implementation).
This is great as long as multiprocessing.cpu_count() preserves the behavior we want. Does it?
Yes, the implementation is almost exactly the same as ours:
In [1]: import multiprocessing In [2]: multiprocessing.cpu_count?? Signature: multiprocessing.cpu_count() Source: def cpu_count(): ''' Returns the number of CPUs in the system ''' if sys.platform == 'win32': try: num = int(os.environ['NUMBER_OF_PROCESSORS']) except (ValueError, KeyError): num = 0 elif 'bsd' in sys.platform or sys.platform == 'darwin': comm = '/sbin/sysctl -n hw.ncpu' if sys.platform == 'darwin': comm = '/usr' + comm try: with os.popen(comm) as p: num = int(p.read()) except ValueError: num = 0 else: try: num = os.sysconf('SC_NPROCESSORS_ONLN') except (ValueError, OSError, AttributeError): num = 0 if num >= 1: return num else: raise NotImplementedError('cannot determine number of cpus')