FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-128277: remove unnecessary critical section from `socket.close` by kumaraditya303 · Pull Request #128305 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .c  (1) .h  (1) .py  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 20 additions & 0 deletions Lib/test/test_socket.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
11 changes: 2 additions & 9 deletions Modules/clinic/socketmodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Modules/socketmodule.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,6 @@ sockets the address is a tuple (ifname, proto [,pkttype [,hatype [,addr]]])");
will surely fail. */

/*[clinic input]
@critical_section
_socket.socket.close
self as s: self(type="PySocketSockObject *")

Expand All @@ -3397,7 +3396,7 @@ Close the socket. It cannot be used after this call.

static PyObject *
_socket_socket_close_impl(PySocketSockObject *s)
/*[clinic end generated code: output=038b2418e07f6f6c input=9839a261e05bcb97]*/
/*[clinic end generated code: output=038b2418e07f6f6c input=dc487e470e55a83c]*/
{
SOCKET_T fd;
int res;
Expand Down

Back | FazBrowse Home | New Git URL