Link to home
Start Free TrialLog in
Avatar of Balbir Singh
Balbir SinghFlag for United States of America

asked on

what is TCP blocking and non-blocking mode in socket module in python3

what is TCP blocking and non-blocking mode in socket module in python

I am trying to understand what it means and under which situation we should use it. I am not able to find a proper example to understand it. I really appreciate if any example can be shared to understand it better.

Thank you!
Avatar of David Favor
David Favor
Flag of United States of America image

https://jameshfisher.com/2017/04/05/set_socket_nonblocking/ demonstration code of non-blocking, which is exactly what it sounds like.

A non-blocking socket, never blocks, which is the basis of event looping.

For example, the high speed Apache Event MPM, so in this case, rather than one connection/process you have one process for all connections, which dramatically speeds up request processing... which is what makes the entire HTTP/2 protocol process all requests in parallel.

If you're really interested in this topic, take a look at the entire HTTP/2 protocol.

You can also take a look at the many PERL async libraries.

Tip: Python, PERL, C, C++, Ruby, whatever... Sockets are Sockets... all the same in any language...
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skullnobrains
skullnobrains

agreed. just to clear things up, select, kevent and othet related calls also work on blocking sockets. I usually run my first benchmarks in blocking mode which helps to check for mistakes in async programs.

The non blocking sockets allows to do A poor man's async programming without using such system calls, by manually polling file descriptors.

So basically blocking or non blocking is not really about asynchronous programming.

Event driven, mpm, http2 are completely off topic.