I run a process distirbuted over the cores through concurrent.futures. Each of the processes has a function which ultimately calls os.getpid()
. Might the IDs from os.getpid()
coincide in spite of being in different concurrent.futures' branches?
I don't know that the meaning of the value returned by os.getpid()
is well defined. I'm pretty sure that you can depend on no two running processes having the same ID, but it's very likely that after some process is terminated, it's ID eventually will be re-used.
That's what happens in most operating systems, and the implementation of os.getpid()
quite likely just calls the operating system and returns the same value.
so concatenation of time and pid should give a unique identifier if i understand correctly.
@guyguyguy12345 - It depends on how unique this identifier needs to be. If you do this twice within a timer tick, then it fails on a single machine. You could add a global counter to fix it. If you do this on a large cluster of machines, there is a chance that two will generate the same number in there somewhere. If that small risk is a problem, then something like
secrets.token_bytes()
may be better.the implementation of
os.getpid
uses the C getpid function. See the source for posix systems. having trouble finding it for windows