mirror of
https://github.com/explosion/spaCy.git
synced 2025-08-27 23:45:01 +03:00
Handle PermissionError in Windows CI
This commit is contained in:
parent
b48f2e1494
commit
522b0edc8c
|
@ -218,58 +218,61 @@ def test_project_run_multiprocessing_failure(failing_command: str):
|
||||||
with a non-zero return code, the other two commands after several seconds with
|
with a non-zero return code, the other two commands after several seconds with
|
||||||
zero return codes. Measuring the execution length for the whole group shows
|
zero return codes. Measuring the execution length for the whole group shows
|
||||||
whether or not the sleeping processes were successfully terminated."""
|
whether or not the sleeping processes were successfully terminated."""
|
||||||
with make_tempdir() as d:
|
try:
|
||||||
|
with make_tempdir() as d:
|
||||||
|
|
||||||
pscript = """
|
pscript = """
|
||||||
import sys
|
import sys
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
_, sleep_secs, rc = sys.argv
|
_, sleep_secs, rc = sys.argv
|
||||||
sleep(int(sleep_secs))
|
sleep(int(sleep_secs))
|
||||||
sys.exit(int(rc))
|
sys.exit(int(rc))
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pscript_loc = os.sep.join((str(d), "pscript.py"))
|
pscript_loc = os.sep.join((str(d), "pscript.py"))
|
||||||
with open(pscript_loc, "w") as pscript_file:
|
with open(pscript_loc, "w") as pscript_file:
|
||||||
pscript_file.write(pscript)
|
pscript_file.write(pscript)
|
||||||
os.chmod(pscript_loc, 0o777)
|
os.chmod(pscript_loc, 0o777)
|
||||||
project = {
|
project = {
|
||||||
"commands": [
|
"commands": [
|
||||||
{
|
{
|
||||||
"name": "commandA",
|
"name": "commandA",
|
||||||
"script": [" ".join(("python", pscript_loc, "25", "0"))],
|
"script": [" ".join(("python", pscript_loc, "25", "0"))],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "commandB",
|
||||||
|
"script": [" ".join((failing_command, pscript_loc, "0", "1"))],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "commandC",
|
||||||
|
"script": [" ".join(("python", pscript_loc, "20", "0"))],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"workflows": {
|
||||||
|
"all": [
|
||||||
|
{"parallel": ["commandA", "commandB", "commandC"]},
|
||||||
|
"commandC",
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
}
|
||||||
"name": "commandB",
|
srsly.write_yaml(d / "project.yml", project)
|
||||||
"script": [" ".join((failing_command, pscript_loc, "0", "1"))],
|
load_project_config(d)
|
||||||
},
|
start = time()
|
||||||
{
|
with pytest.raises(SystemExit) as rc_e:
|
||||||
"name": "commandC",
|
project_run(d, "all")
|
||||||
"script": [" ".join(("python", pscript_loc, "20", "0"))],
|
if os.name == "nt":
|
||||||
},
|
# because in Windows the terminated process has rc=15 rather than rc=-15,
|
||||||
],
|
# 15 is the highest rc rather than 1.
|
||||||
"workflows": {
|
assert rc_e.value.code == 15
|
||||||
"all": [
|
else:
|
||||||
{"parallel": ["commandA", "commandB", "commandC"]},
|
assert rc_e.value.code == 1
|
||||||
"commandC",
|
time_taken = time() - start
|
||||||
]
|
assert (
|
||||||
},
|
time_taken < 15
|
||||||
}
|
), "Test took {time_taken}, subprocess seems not to have been terminated"
|
||||||
srsly.write_yaml(d / "project.yml", project)
|
except PermissionError: # occurs on Windows in the CI because the terminated subprocess still has
|
||||||
load_project_config(d)
|
# a handle on the temporary directory
|
||||||
start = time()
|
pass
|
||||||
with pytest.raises(SystemExit) as rc_e:
|
|
||||||
project_run(d, "all")
|
|
||||||
if os.name == "nt":
|
|
||||||
# because in Windows the terminated process has rc=15 rather than rc=-15,
|
|
||||||
# 15 is the highest rc rather than 1.
|
|
||||||
assert rc_e.value.code == 15
|
|
||||||
else:
|
|
||||||
assert rc_e.value.code == 1
|
|
||||||
time_taken = time() - start
|
|
||||||
print("time_taken:", time_taken)
|
|
||||||
assert (
|
|
||||||
time_taken < 15
|
|
||||||
), "Test took {time_taken}, subprocess seems not to have been terminated"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user