Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #95448 > unrolled thread

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

Started byalex.flint@gmail.com
First post2015-08-17 15:23 -0700
Last post2015-08-18 00:11 -0400
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? alex.flint@gmail.com - 2015-08-17 15:23 -0700
    Re: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? alex.flint@gmail.com - 2015-08-17 15:25 -0700
      Re: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? Ian Kelly <ian.g.kelly@gmail.com> - 2015-08-17 17:11 -0600
      Re: why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)? random832@fastmail.us - 2015-08-18 00:11 -0400

#95448 — why does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)?

Fromalex.flint@gmail.com
Date2015-08-17 15:23 -0700
Subjectwhy does id(multiprocessing.Process.start) == id(multiprocessing.Process.start)?
Message-ID<dbbdd7bd-63e7-42cb-96d5-523606380bed@googlegroups.com>
using Python 2.7.9, I get the following:

>>> id(multiprocessing.Process.start) == id(multiprocessing.Process.start)
True

But on the other hand:

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

I thought that these two expressions were equivalent. Can somebody help me to understand what's going on here?

[toc] | [next] | [standalone]


#95449

Fromalex.flint@gmail.com
Date2015-08-17 15:25 -0700
Message-ID<f45a1172-03e2-4bb2-8045-8252843d9cdf@googlegroups.com>
In reply to#95448
On Monday, August 17, 2015 at 3:24:22 PM UTC-7, alex....@gmail.com wrote:
> using Python 2.7.9, I get the following:
> 
> >>> id(multiprocessing.Process.start) == id(multiprocessing.Process.start)
> True
> 
> But on the other hand:
> 
> >>> multiprocessing.Process.start is multiprocessing.Process.start
> False
> 
> I thought that these two expressions were equivalent. Can somebody help me to understand what's going on here?

Sorry I completely mistype that. It was supposed to read:

>>> id(multiprocessing.Process.is_alive) == id(multiprocessing.Process.start)
True

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

[toc] | [prev] | [next] | [standalone]


#95451

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-08-17 17:11 -0600
Message-ID<mailman.68.1439853151.4764.python-list@python.org>
In reply to#95449
On Mon, Aug 17, 2015 at 4:57 PM, Chris Kaynor <ckaynor@zindagigames.com> wrote:
> 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.

In the case of "is", I don't agree. "is" is a useful operator and is
not prone to user error like "id". The only caveat is that one should
understand the distinction between "is" and "==".

[toc] | [prev] | [next] | [standalone]


#95456

Fromrandom832@fastmail.us
Date2015-08-18 00:11 -0400
Message-ID<mailman.71.1439871122.4764.python-list@python.org>
In reply to#95449
On Mon, Aug 17, 2015, at 18:25, alex.flint@gmail.com wrote:
> Sorry I completely mistype that. It was supposed to read:
> 
> >>> id(multiprocessing.Process.is_alive) == id(multiprocessing.Process.start)
> True
> 
> >>> multiprocessing.Process.is_alive is multiprocessing.Process.start
> False

Try this:
is_alive = multiprocessing.Process.is_alive
start = multiprocessing.Process.start
id(is_alive) == id(start)

If (as I believe it will) this ends up being false, this shows that it's
an issue of object lifespan with the values of the expression being
temporary method wrappers. From some testing, on my machine on CPython
2.7 this appears to work for any method of any class written in python.
While you fixed the typo, it is instructive to note that, as in your
original example, multiprocessing.Process.start is
multiprocessing.Process.start is *also* False, which would not be the
case if the method wrapper were a permanent object.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web