RE: How is the execution order of 'x = z'? (also: Python FAQ 4.88)

Discussion in 'Python' started by Bjorn Pettersen, Jul 22, 2003.

  1. > From: Ames Andreas (MPA/DF) [mailto:]
    >
    > Hello,
    >
    > during execution of an assignment statement like
    >
    > x = y
    > .
    > .
    > .
    > x = z # <--
    >
    > is y's reference count decremented (and therefore its __del__ possibly
    > called) *before* x is bound to z (or is z bound to x, I don't know the
    > correct wording) or *afterwards*?


    I'm not sure exactly what you're asking, but "x = y", is similar to the
    following C-pseudo-code:

    1 incref(*y);
    2 tmp = x
    3 x = y;
    4 decref(*tmp); // potentially calling __del__

    [[if I'm reading ceval.c correctly... lines 2-4 being in SETLOCAL,
    called from STORE_FAST, based on the following code:

    >>> def f(a,b):

    .... a = b
    ....
    >>> import dis
    >>> dis.dis(f)

    2 0 LOAD_FAST 1 (b)
    3 STORE_FAST 0 (a)
    6 LOAD_CONST 0 (None)
    9 RETURN_VALUE
    ]]

    whether this should matter to you is dubious since the case you seem to
    be worried about (y being deleted before z assigned to x) would only
    matter if it caused z to have a dangling reference to y. However, if z
    has a reference to y, its reference count can't go to zero, thus no
    __del__ would ever be called.

    -- bjorn
     
    Bjorn Pettersen, Jul 22, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. priya
    Replies:
    0
    Views:
    1,242
    priya
    Oct 3, 2005
  2. =?Utf-8?B?QmlsbCBCb3Jn?=

    Execution order of PageLoad for user controls

    =?Utf-8?B?QmlsbCBCb3Jn?=, Mar 6, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    3,369
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Mar 6, 2004
  3. Bijoy Naick

    Execution order of Validation Controls

    Bijoy Naick, Jun 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,970
    Martin Marinov
    Jun 8, 2004
  4. John Saunders

    Re: A question about order of execution?

    John Saunders, Jul 15, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    367
    S. Justin Gengo
    Jul 15, 2004
  5. Larry Hastings
    Replies:
    10
    Views:
    839
    Larry Hastings
    Jan 17, 2006
Loading...

Share This Page