File: test_imports.py

package info (click to toggle)
dask.distributed 2022.12.1%2Bds.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 10,164 kB
  • sloc: python: 81,938; javascript: 1,549; makefile: 228; sh: 100
file content (38 lines) | stat: -rw-r--r-- 923 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from __future__ import annotations

import subprocess
import sys

script = """
import threading
import traceback

import_succeeded = False

def import_dask_distributed():
    try:
        import dask.distributed  # noqa
    except Exception:
        # Print the exception for debugging
        traceback.print_exc()
    else:
        global import_succeeded
        import_succeeded = True

thread = threading.Thread(target=import_dask_distributed, daemon=True)
thread.start()
thread.join()

assert import_succeeded

# Now try to use distributed from the main thread, and check that it works
from dask.distributed import Client
with Client(processes=False) as client:
    res = client.submit(lambda x: x + 1, 1).result()
    assert res == 2
"""


def test_can_import_distributed_in_background_thread():
    """See https://github.com/dask/distributed/issues/5587"""
    subprocess.check_call([sys.executable, "-c", script])