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

dieter dieter at handshake.de
Sat May 4 02:40:12 EDT 2019


Markus Elfring <Markus.Elfring at web.de> writes:
> ...
> 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.

If you have a multi-threaded application and you want to be on
the "safe side", you always use your own locks.

Python uses locks to protect its own data structures.
Whether this protection is enough for your use of Python types
depends on details you may not want to worry about.
For example: most operations on Python types are atomic (if they
do not involve some kind of "waiting" or "slow operation") *BUT*
if they can detroy objects, then arbitrary code (from
destructors) can be executed and then they are not atomic.

As an example "list.append" is atomic (no object is detroyed),
but "list[:] = ..." is not: while the list operation itself
is not interrupted by another thread, the operation may destroy
objects (the old list components) and other threads may get control
before the assignment has finished.




More information about the Python-list mailing list