Glibc getpid syscall caching
Glibc used to cache the result of the getpid syscall. Because the caching did not play well, it was removed from newer versions of glibc. As a result the call got more expensive and it is even visible from Python.
Debian Jessie shipped the old glibc while Stretch has the new one without cache. Alpine uses musl libc, which apparently does not cache the syscall:
$ docker run -ti --rm python:3.6-jessie python -m timeit -s "import os" "os.getpid()" 10000000 loops, best of 3: 0.0523 usec per loop $ docker run -ti --rm python:3.6-stretch python -m timeit -s "import os" "os.getpid()" 10000000 loops, best of 3: 0.193 usec per loop $ docker run -ti --rm python:3.6-alpine python -m timeit -s "import os" "os.getpid()" 1000000 loops, best of 3: 0.203 usec per loop