mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-01 07:33:45 -06:00
fix: one thread at a time in the campaign cwd
This commit is contained in:
1 parent
ae5e377f21
commit
14b7fd1c98
2 files changed
+18
-7
No files matched your search
+15
-7
@@ -69,6 +69,7 @@ import stat
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import threading
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
@@ -454,15 +455,22 @@ def copy_regular(src: Path, dest: Path) -> None:
|
||||
shutil.copyfileobj(handle, out)
|
||||
|
||||
|
||||
# The working directory belongs to the process. Two passes in threads that
|
||||
# each saved and restored it could leave the process in the other's root,
|
||||
# then in a folder deleted with its workspace.
|
||||
_CWD_LOCK = threading.Lock()
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def working_directory(path: Path) -> Iterator[None]:
|
||||
"""contextlib.chdir, which Python 3.9 lacks."""
|
||||
before = Path.cwd()
|
||||
os.chdir(path)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(before)
|
||||
"""contextlib.chdir, which Python 3.9 lacks, one thread at a time."""
|
||||
with _CWD_LOCK:
|
||||
before = Path.cwd()
|
||||
os.chdir(path)
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
os.chdir(before)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
Reference in new issue
Block a user