python asp page keeps state across queries !?!?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • nicolas_riesch

    #1

    python asp page keeps state across queries !?!?

    I am writing asp pages in python, running on IIS 5 on Windows.

    I notice that variables outside functions keep their value across
    queries.
    I don't know if it is normal.

    Here is a little script that demonstrates it:

    ------------------ problem.asp ---------------------

    <%@LANGUAGE=Pyt hon%>

    <%

    try:
    if x == 0: # if x is not defined, an exception is raised here and
    code goes to the except clause
    pass
    else:
    x = x + 1 # if x exists, increment x
    except:
    x = 10 # if x not defined, initialize x to 10

    Response.write( 'Hello, the value of x is ' + str(x) ) # write value
    of x

    %>
    -----------------------------------------------------

    The first time I fetch this asp page from the web browser, I get:

    Hello, the value of x is 10

    So far, it works.
    But then, when I click on the refresh button to query the asp page
    again, I get:

    Hello, the value of x is 11

    and then

    Hello, the value of x is 12

    and so on ...

    Each time I reload this asp page, the x variable is incremented !!!

    It seems that IIS loads this asp page like a module and keep it in
    memory.
    That's why all variables at the module level act as global variables
    that survives to multiple queries.

    To be sure, I tried a similar asp script written in VB script, and I
    can see that in VBscript, variables at this same level ARE NOT kept
    across different queries !!!
    So, the behavior of Python asp page is different from the same page
    written in VBscript.

    I don't know if it is a normal thing or if it is a bug, of if I have
    missed something.
    Someone has an explanation ?

  • Sybren Stuvel

    #2
    Re: python asp page keeps state across queries !?!?

    nicolas_riesch enlightened us with:[color=blue]
    > I notice that variables outside functions keep their value across
    > queries. I don't know if it is normal.[/color]

    I think it's normal.
    [color=blue]
    > To be sure, I tried a similar asp script written in VB script, and I
    > can see that in VBscript, variables at this same level ARE NOT kept
    > across different queries !!![/color]

    So?
    [color=blue]
    > Someone has an explanation ?[/color]

    Speed. No need to reload the module for each query. Just don't use any
    uninitialized module-scope variables. It's bad style anyway.

    Sybren
    --
    The problem with the world is stupidity. Not saying there should be a
    capital punishment for stupidity, but why don't we just take the
    safety labels off of everything and let the problem solve itself?
    Frank Zappa

    Comment

    Working...