Checking network input processing by Python for a multi-threaded server

Markus Elfring Markus.Elfring at
Fri May 3 04:01:45 EDT 2019

> In any multi-threaded application, you must be carefull when
> accessing (and especially modifying) shared (e.g. "global") objects.
> In general, you will need locks to synchronize the access.

I agree to this general view.

> Appending to a list (and some other elementary operations
> on Python data structures) is protected by Python's "GIL"
> (= "Global Interpreter Lock") and thereby becomes "atomic".
> Thus, if all you do is appending - then the append has no need
> of explicite locking.

Thanks for such information.

> It does not protect the integrity of your data structures.

It can be that the data protection needs to be extended occasionally.
But I am more interested in the detail that a specific Python list variable
should reflect the received record sets from a single test command
in a consistent way.

Did all extra worker threads exit after the statement “server.shutdown()”
was successfully executed?

> Thus, if your threads modify shared objects, then you are responsible
> to protect access to them with appropriate locking.

How do you think about to improve the distinction for the really
desired lock granularity in my use case?


More information about the Python-list mailing list