From 26abac7a95571730521874175544b31606ac00e8 Mon Sep 17 00:00:00 2001 From: Omer Katz Date: Mon, 9 Nov 2015 11:51:05 +0200 Subject: [PATCH] Added error handling to -n auto. --- xdist/plugin.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xdist/plugin.py b/xdist/plugin.py index dc3635e..971ed6c 100644 --- a/xdist/plugin.py +++ b/xdist/plugin.py @@ -4,8 +4,15 @@ import pytest def parse_numprocesses(s): if s == 'auto': - import multiprocessing - return multiprocessing.cpu_count() + try: + from os import cpu_count + except ImportError: + from multiprocessing import cpu_count + try: + n = cpu_count() + except NotImplementedError: + return 1 + return n if n else 1 else: return int(s)