[Pythonmac-SIG] Replacement for getpid() in macpython?
Jack Jansen
Jack.Jansen@oratrix.com
Sat, 29 Mar 2003 22:23:14 +0100
On zaterdag, maa 29, 2003, at 07:18 Europe/Amsterdam, Peter Ahlstrom
wrote:
> Hi there,
>
> I just barely got macpython and am trying to get a particular popular
> python program to work in mac os 9. If I modify two lines, things go
> okay, but I'm looking for a better solution.
>
> the lines are
>
> from os import getpid, path, makedirs
>
> and
>
> myid = (chr(0) * 12) + sha(repr(time()) + ' ' +
> str(getpid())).digest()[-8:]
You could leave it out, or pick some other "easy" bit of information.
You could use the
host name of your machine, socket.gethostname(), or the number of ticks
(1/60th of a second)
since boot, MacOS.GetTicks(). Either of these make the chance that you
get a collision
probably smaller than the chance that two digests are equal (2**-32, in
your case, it seems).
Still, even when you use "0" for getpid() you will only get a collision
if two Mac users
create an ID at exactly the same time. Whether this chance is bigger or
smaller than 2**-32
is left as an exercise to the reader, but I know I would be happy
enough with it:-)
--
- Jack Jansen <Jack.Jansen@oratrix.com>
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma
Goldman -