Checking support for efficient appending to mapped data

Markus Elfring Markus.Elfring at web.de
Tue Apr 30 03:09:19 EDT 2019


> The file name for the client script is passed by a parameter to a command
> which is repeated by this server in a loop.

Additional explanations can be helpful for the shown software situation.


> It is evaluated then how often a known record set count was sent.

It was actually determined for a specific function variant how many input
record sets were available for data processing by the server in a loop iteration.


> I got a test result like the following.
>
>
> elfring at Sonne:~/Projekte/Coccinelle/janitor> time /usr/bin/python3 list_last_two_statements_from_if_branches-statistic-server3.py
> "return code"|"received records"|"command output"|incidence
> 0|9||63
> 0|5||5
> 0|13||2
…

Such a test result shows that some records could be handled by the server
within the time range from the start of a command and the exit of
the corresponding child process which sends desired data back to
its caller.
A fraction of records can be handled only at a subsequent iteration
if no session management was applied as in this test case.


> * How should this data processing approach be adjusted so that the same number
>   of records will be handled in a consistent way?

There is a need to add session management so that required context information
will be connected with the provided input data. Each session needs to be
identified by an unique key. The Python programming language provides the data
type “dict” for such a mapping as standard functionality.
https://docs.python.org/3/library/stdtypes.html#mapping-types-dict

Python's support for associative containers is generally nice.
But I find that consequences from modification of mapped data can become more
interesting for the mentioned use case.
The operator “+=” (augmented assignment) can be used there, can't it?
The appending of data is supported for some types by this operation.
I am informed in the way that some data types expect that a well-known
method like “append” must (or should be) be called instead for such
an “addition” (if you care for efficient data processing).
https://docs.python.org/3/library/stdtypes.html#mutable-sequence-types

Now I am looking again for further clarifications and improvements
in this area.
Would you like to share any more ideas here?

Regards,
Markus



More information about the Python-list mailing list