How to use auto_detect_cpus method in tox

Best Python code snippet using tox_python

parallel.py

Source:parallel.py Github

copy

Full Screen

2from argparse import ArgumentTypeError3ENV_VAR_KEY = "TOX_PARALLEL_ENV"4OFF_VALUE = 05DEFAULT_PARALLEL = OFF_VALUE6def auto_detect_cpus():7 try:8 from os import sched_getaffinity # python 3 only9 def cpu_count():10 return len(sched_getaffinity(0))11 except ImportError:12 # python 2 options13 try:14 from os import cpu_count15 except ImportError:16 from multiprocessing import cpu_count17 try:18 n = cpu_count()19 except NotImplementedError: # pragma: no cov20 n = None # pragma: no cov21 return n if n else 122def parse_num_processes(s):23 if s == "all":24 return None25 if s == "auto":26 return auto_detect_cpus()27 else:28 value = int(s)29 if value < 0:30 raise ArgumentTypeError("value must be positive")31 return value32def add_parallel_flags(parser):33 parser.add_argument(34 "-p",35 "--parallel",36 dest="parallel",37 help="run tox environments in parallel, the argument controls limit: all,"38 " auto - cpu count, some positive number, zero is turn off",39 action="store",40 type=parse_num_processes,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tox automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful