why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)?

Chris Kaynor ckaynor at zindagigames.com
Tue Aug 18 00:57:22 CEST 2015


On Mon, Aug 17, 2015 at 3:25 PM, <alex.flint at gmail.com> wrote:
>
> Sorry I completely mistype that. It was supposed to read:
>
> >>> id(multiprocessing.Process.is_alive) ==
> id(multiprocessing.Process.start)
> True
>

What is going on here is that it get multiprocessing.Process.is_alive,
computes the id of it, then throws away the value of
multiprocessing.Process.is_alive. It then does the same thing for
multiprocessing.Process.start, where by it happens to reuse the id of the
first value.


> >>> multiprocessing.Process.is_alive is multiprocessing.Process.start
> False
>

In this case, the "is" operator keeps both references around during its
call, and therefore they will get different ids.


The rules for the id is that they are only guaranteed unique during the
lifespan of both objects. Also, generally, you do not want to use id or is
for much of anything unless you really know what you are doing - generally,
you just want == instead.


>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20150817/2d432a2b/attachment.html>


More information about the Python-list mailing list