Skip to content
This repository was archived by the owner on May 29, 2024. It is now read-only.

Commit 9c69c4e

Browse files
authored
Add compatibility for Python 3.8+ (#71)
1 parent 0913320 commit 9c69c4e

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,8 @@ jobs:
2121
- name: py37
2222
python: "3.7"
2323
env: TOXENV=py37-coverage
24+
- name: py38
25+
python: "3.8"
26+
env: TOXENV=py38-coverage
2427
- name: lint
2528
script: pipenv run lint

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ pytest --tests-per-worker auto
5353
pytest --workers 2 --tests-per-worker auto
5454
```
5555

56+
## Notice
57+
58+
Beginning with Python 3.8, forking behavior is forced on macOS at the expense of safety.
59+
60+
Changed in version 3.8: On macOS, the spawn start method is now the default. The fork start method should be considered unsafe as it can lead to crashes of the subprocess. See bpo-33725.
61+
62+
[Source](https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods)
63+
5664
## License
5765

5866
MIT

pytest_parallel/__init__.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,33 @@
11
import os
22
import py
3+
import sys
34
import time
45
import math
56
import pytest
67
import _pytest
78
import platform
89
import threading
10+
import multiprocessing
911
from tblib import pickling_support
1012
from multiprocessing import Manager, Process
1113

14+
# In Python 3.8 and later, the default on macOS is spawn.
15+
# We force forking behavior at the expense of safety.
16+
#
17+
# "On macOS, the spawn start method is now the default. The fork start method should be
18+
# considered unsafe as it can lead to crashes of the subprocess. See bpo-33725."
19+
#
20+
# https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
21+
if sys.platform.startswith('darwin'):
22+
multiprocessing.set_start_method('fork')
23+
1224
__version__ = '0.0.10'
1325

1426

1527
def parse_config(config, name):
1628
return getattr(config.option, name, config.getini(name))
1729

1830

19-
def force(fn):
20-
while True:
21-
try:
22-
return fn()
23-
except ConnectionRefusedError:
24-
time.sleep(.1)
25-
continue
26-
27-
2831
def pytest_addoption(parser):
2932
workers_help = ('Set the max num of workers (aka processes) to start '
3033
'(int or "auto" - one per core)')
@@ -179,7 +182,7 @@ class ParallelRunner(object):
179182
def __init__(self, config):
180183
self._config = config
181184
self._manager = Manager()
182-
self._log = py.log.Producer("pytest-parallel")
185+
self._log = py.log.Producer('pytest-parallel')
183186

184187
reporter = config.pluginmanager.getplugin('terminalreporter')
185188

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ envlist =
33
flake8
44
py36
55
py37
6+
py38
67

78
[testenv]
89
deps =

0 commit comments

Comments
 (0)