8000 gh-128277: remove unnecessary critical section from `socket.close` by kumaraditya303 · Pull Request #128305 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128277: remove unnecessary critical section from socket.close #128305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 1, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
kumaraditya303 committed Dec 28, 2024
commit 3774f5d822eeebb36cad4cd0174ca95c8ff9df00
20 changes: 20 additions & 0 deletions Lib/test/test_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -7075,6 +7075,26 @@ def close_fds(fds):
self.assertEqual(data, str(index).encode())


class FreeThreadingTests(unittest.TestCase):

def test_close_detach_race(self):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

def close():
for _ in range(1000):
s.close()

def detach():
for _ in range(1000):
s.detach()

t1 = threading.Thread(target=close)
t2 = threading.Thread(target=detach)

with threading_helper.start_threads([t1, t2]):
pass


def setUpModule():
thread_info = threading_helper.threading_setup()
unittest.addModuleCleanup(threading_helper.threading_cleanup, *thread_info)
Expand Down
Loading
0