MCPcopy Create free account
hub / github.com/dask/dask / dir_server

Function dir_server

dask/bytes/tests/test_http.py:35–59  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

33
34@pytest.fixture(scope="module")
35def dir_server():
36 with tmpdir() as d:
37 for fn in files:
38 with open(os.path.join(d, fn), "wb") as f:
39 f.write(b"a" * 10000)
40
41 cmd = [sys.executable, "-m", "http.server", str(port)]
42 p = subprocess.Popen(cmd, cwd=d)
43 timeout = 10
44 while True:
45 try:
46 requests.get(root)
47 break
48 except requests.exceptions.ConnectionError as e:
49 time.sleep(0.1)
50 timeout -= 0.1
51 if timeout < 0:
52 raise RuntimeError("Server did not appear") from e
53 yield d
54 p.terminate()
55 try:
56 # reap the child, lest it keep the port bound for the next run
57 p.wait(timeout=3)
58 except subprocess.TimeoutExpired:
59 p.kill()
60
61
62def test_simple(dir_server):

Callers

nothing calls this directly

Calls 3

tmpdirFunction · 0.90
joinMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected