The following shennanigans were collected during my work on creating a system integration library and framework for hardware and software tests including developer tasks like worktree management, building, target deployment and configuration. Therefore it should be representative for things one might want to do in absence of better tooling. The used Python version was 3.8.2, but most problems still persist.
My tldr; retrospection upfront, which you may be able to reproduce once you try to code long-running services, which recover from all failures, cleanly reset state or generally try to debug spurious problems. Please don’t.
Python on itself is great for prototyping up to a few hundred lines of code, like to quickly receive or send some json over tcp/html. However, it is unfeasible to scale, for example to use as library code. Changes in a leaf function can add exceptions to higher level code paths and handling those via exceptions for user friendly error messages, for example to collect context (information along multiple functions, for example from different combination of traversal) becomes unreasonably verbose and error prone. The alternative is to use C-like error handling, which requires to figure out all possible exceptions of Python libstd methods, which language servers do not support (as of 2024-04-04).
Aside of these more fundamental limitations, here the list of shennanigans I have run into:
xml.dom.minidom
breaks space and newlines. Use ElementTree
..strip()
is necessary after file read, because Python automatically adds \n
and there is no way to read without newlines into a list.dict
is unreadable, so such a method is missing dict
has no method to check, if the fields of a dictionary are in another dictionary dict
has no method to check, if all fields and values of a dictionary are in another dictionary gf
or gF
vim shortcuts to jump to location function to write status + trace to variable. "
) and single quote ('
) strings are invalid json os.kill()
does not call registered cleanup function atexit.register(exit_cleanup)
by daemonized threads. Must store pids of child processes and clean them explicitly or signal main thread via module: object
is the closest we can get as simple annotation. json.dumps
generated string has silent failures, for example on parsing the output as json via php.