I can’t remember if threads are core bound or not.
On Linux, by default they’re not. getcpu(2) says:
The getcpu() system call identifies the processor and node on which the
calling thread or process is currently running and writes them into the
integers pointed to by the cpu and node arguments. ...
The information placed in cpu is guaranteed to be current only at the
time of the call: unless the CPU affinity has been fixed using
sched_setaffinity(2), the kernel might change the CPU at any time.
(Normally this does not happen because the scheduler tries to minimize
movements between CPUs to keep caches hot, but it is possible.) The
caller must allow for the possibility that the information returned in
cpu and node is no longer current by the time the call returns.
Scapy is another library where they redefined
/
to layer packets, such that you can write:IP(dst="172.23.34.45") / UDP() / DNS(…)
Then Scapy has magic so that on serialisation, the UDP layer knows defaults to dport=53 if the upper layer is DNS, and it can access the lower layer to compute its checksum.
And don’t forget that strings have a custom
%
(as in modulo) operator for formatting:"Hello %s" %(username)
Of course in modern Python, f-strings will almost always be more convenient