Avatar of Balbir Singh
Balbir Singh
Flag 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!
Python

Avatar of undefined
Last Comment
skullnobrains

8/22/2022 - Mon
David Favor

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
skullnobrains

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
noci

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes