diff options
author | Victor Stinner <vstinner@redhat.com> | 2018-12-18 22:52:39 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-18 22:52:39 (GMT) |
commit | 05c9d31eb62cc45dc3c55a5cdb7cbc713d0421db (patch) | |
tree | ebab2882076c062d0515734909b4eef59430718b /Lib/test | |
parent | b5c8cfa1da17c6f3acac80a0afca7f7104fb9589 (diff) | |
download | cpython-05c9d31eb62cc45dc3c55a5cdb7cbc713d0421db.zip cpython-05c9d31eb62cc45dc3c55a5cdb7cbc713d0421db.tar.gz cpython-05c9d31eb62cc45dc3c55a5cdb7cbc713d0421db.tar.bz2 |
bpo-31731: Fix test_io.check_interrupted_write() (GH-11225)
Fix a race condition in check_interrupted_write() of test_io:
create directly the thread with SIGALRM signal blocked,
rather than blocking the signal later from the thread. Previously, it
was possible that the thread gets the signal before the signal is
blocked.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_io.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Lib/test/test_io.py b/Lib/test/test_io.py index dc353c1..c364487 100644 --- a/Lib/test/test_io.py +++ b/Lib/test/test_io.py @@ -4149,10 +4149,9 @@ class SignalsTest(unittest.TestCase): in the latter.""" read_results = [] def _read(): - if hasattr(signal, 'pthread_sigmask'): - signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGALRM]) s = os.read(r, 1) read_results.append(s) + t = threading.Thread(target=_read) t.daemon = True r, w = os.pipe() @@ -4160,7 +4159,14 @@ class SignalsTest(unittest.TestCase): large_data = item * (support.PIPE_MAX_SIZE // len(item) + 1) try: wio = self.io.open(w, **fdopen_kwargs) - t.start() + if hasattr(signal, 'pthread_sigmask'): + # create the thread with SIGALRM signal blocked + signal.pthread_sigmask(signal.SIG_BLOCK, [signal.SIGALRM]) + t.start() + signal.pthread_sigmask(signal.SIG_UNBLOCK, [signal.SIGALRM]) + else: + t.start() + # Fill the pipe enough that the write will be blocking. # It will be interrupted by the timer armed above. Since the # other thread has read one byte, the low-level write will |