Debian Codegraph @

extra_tests/test_posix_extra.py

raw symbols SCIP
1 import pytest
2 import sys, os, subprocess
3
4
5 CODE = """
6 import sys, os, _thread, time
7
8 fd1, fd2 = os.pipe()
9 f1 = os.fdopen(fd1, 'rb', 0)
10 f2 = os.fdopen(fd2, 'wb', 0)
11
12 def f():
13 print("thread started")
14 x = f1.read(1)
15 assert x == b"X"
16 print("thread exit")
17
18 _thread.start_new_thread(f, ())
19 time.sleep(0.5)
20 if os.fork() == 0: # in the child
21 time.sleep(0.5)
22 x = f1.read(1)
23 assert x == b"Y"
24 print("ok!")
25 sys.exit()
26
27 f2.write(b"X") # in the parent
28 f2.write(b"Y") # in the parent
29 time.sleep(1.0)
30 """
31
32
33 @pytest.mark.skipif("not getattr(os, 'fork', None)")
34 def test_thread_fork_file_lock():
35 output = subprocess.check_output([sys.executable, '-u', '-c', CODE])
36 assert output.splitlines() == [
37 b'thread started',
38 b'thread exit',
39 b'ok!']