Skip to content

Can the explanation of socket.connect() connection failures be rephrased? I don't think anybody understands what's written. #132819

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

Open
jeffstearns opened this issue Apr 23, 2025 · 1 comment
Labels
docs Documentation in the Doc dir

Comments

@jeffstearns
Copy link

Documentation

The documentation for the socket.connect() method has a tortured sentence that is very hard to understand. It's especially intractable for non-native English speakers. Can it be simplified?

The sentence is this:
If the connection is interrupted by a signal, the method waits until the connection completes, or raise a [TimeoutError](https://docs.python.org/3/library/exceptions.html#TimeoutError) on timeout, if the signal handler doesn’t raise an exception and the socket is blocking or has a timeout.

Can this be rephrased as two simpler sentences? I'm happy to propose that rewrite if somebody could add a comment here explaining what this sentence actually means. thx

@jeffstearns jeffstearns added the docs Documentation in the Doc dir label Apr 23, 2025
@vadmium
Copy link
Member

vadmium commented Apr 24, 2025

That sentence is trying to describe the how Python will retry operating system calls that return EINTR. See commit 81c41db, Git Hub issue #67806, and PEP 475 for the background.

It sounds like the behaviour is:

  • In general, the socket.connect method waits for the connection to succeed, and then returns with no error nor exception
  • The method stops waiting and raises TimeoutError if the Python socket object has a timeout set which is exceeded
  • If the thread is interrupted by an OS signal, Python will eventually run the associated Python signal handler. A Python signal handler can also cause the method to stop waiting and raise an exception.
  • If the thread was interrupted, but the Python handler (if any) did not raise an exception, the behaviour depends on the blocking or timeout mode of the Python socket object:
    • In non-blocking mode, with the timeout set to zero, InterruptedError is raised
    • In blocking or timeout mode (with an indefinite or non-zero timeout set), the method continues and waits for the connection to succeed, without raising an exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
Status: Todo
Development

No branches or pull requests

2 participants