| 446 | |
| 447 | |
| 448 | def get_work_dir(parent_dir: StrPath, worker: bool = False) -> StrPath: |
| 449 | # Define a writable temp dir that will be used as cwd while running |
| 450 | # the tests. The name of the dir includes the pid to allow parallel |
| 451 | # testing (see the -j option). |
| 452 | # Emscripten and WASI have stubbed getpid(), Emscripten has only |
| 453 | # millisecond clock resolution. Use randint() instead. |
| 454 | if support.is_emscripten or support.is_wasi: |
| 455 | nounce = random.randint(0, 1_000_000) |
| 456 | else: |
| 457 | nounce = os.getpid() |
| 458 | |
| 459 | if worker: |
| 460 | work_dir = WORK_DIR_PREFIX + str(nounce) |
| 461 | else: |
| 462 | work_dir = WORKER_WORK_DIR_PREFIX + str(nounce) |
| 463 | work_dir += os_helper.FS_NONASCII |
| 464 | work_dir = os.path.join(parent_dir, work_dir) |
| 465 | return work_dir |
| 466 | |
| 467 | |
| 468 | @contextlib.contextmanager |