Skip to main content
edited title; deleted 2 characters in body; deleted 863 characters in body; deleted 17 characters in body
Source Link
8steve8
  • 2.3k
  • 3
  • 16
  • 17

using exec() in wsgi andwith python 3.2

so normally if i run a python scriptthese script with this code:

x=5
exec("x+=1")
output=str(x)

atIf I execute the end of thisabove in a python console, output has a value of "6" as expected

but But if it's run inside a wsgi app:

x=5
exec("x+=1")
output=str(x)

now output = "5"function, the exec doesn't change the value of x.

Why does this happen, and how cancould I get the exec to behave like normal python (3).

Please don't let this thread turn into a debate about using exec. I want to use exec, is it possible inside wsgi?

BTW: eval() seems to works normally inside wsgi. Also: I see this running mod_wsgisame behavior in daemon and embedded mode, I also see it without mod_wsgi using python wsgiref.simple_server.

here is the full code of a little wsgi app wherefunction as i do in the exec command doesnt seem to have an effect:console?

from wsgiref.simple_server import make_server

def app(environ, start_response):
    status = '200 OK'
    response_headers = [('content-type', 'text/html')]
    start_response(status,response_headers)
    x=5
    exec("x+=1")
    ret = str(x)
    return [bytes(ret.encode('UTF-8'))]
application = app
httpd = make_server('', 88, app)
print("Serving on port 88...")
httpd.serve_forever()

using exec() in wsgi and python 3.2

so normally if i run a python script with this code:

x=5
exec("x+=1")
output=str(x)

at the end of this output has a value of "6" as expected

but inside a wsgi app:

x=5
exec("x+=1")
output=str(x)

now output = "5"

Why does this happen and how can I get the exec to behave like normal python (3).

Please don't let this thread turn into a debate about using exec. I want to use exec, is it possible inside wsgi?

BTW: eval() seems to works normally inside wsgi. Also: I see this running mod_wsgi in daemon and embedded mode, I also see it without mod_wsgi using python wsgiref.simple_server.

here is the full code of a little wsgi app where the exec command doesnt seem to have an effect:

from wsgiref.simple_server import make_server

def app(environ, start_response):
    status = '200 OK'
    response_headers = [('content-type', 'text/html')]
    start_response(status,response_headers)
    x=5
    exec("x+=1")
    ret = str(x)
    return [bytes(ret.encode('UTF-8'))]
application = app
httpd = make_server('', 88, app)
print("Serving on port 88...")
httpd.serve_forever()

using exec() with python 3.2

so normally if i run these script with this code:

x=5
exec("x+=1")
output=str(x)

If I execute the above in a python console, output has a value of "6" But if it's run inside a function, the exec doesn't change the value of x.

Why does this happen, and how could I get the same behavior in a function as i do in the console?

Has nothing to do with wsgi, really. Generic Python question.
Link
Lennart Regebro
  • 173.3k
  • 45
  • 230
  • 254
added 562 characters in body
Source Link
8steve8
  • 2.3k
  • 3
  • 16
  • 17

so normally if i run a python script with this code:

x=5
exec("x+=1")
output=str(x)

at the end of this output has a value of "6" as expected

but inside a wsgi app:

x=5
exec("x+=1")
output=str(x)

now output = "5"

Why does this happen and how can I get the exec to behave like normal python (3).

Please don't let this thread turn into a debate about using exec. I want to use exec, is it possible inside wsgi?

BTW: eval() seems to works normally inside wsgi. Also: I see this running mod_wsgi in daemon and embedded mode, I also see it without mod_wsgi using python wsgiref.simple_server.

here is the full code of a little wsgi app where the exec command doesnt seem to have an effect:

from wsgiref.simple_server import make_server

def app(environ, start_response):
    status = '200 OK'
    response_headers = [('content-type', 'text/html')]
    start_response(status,response_headers)
    x=5
    exec("x+=1")
    ret = str(x)
    return [bytes(ret.encode('UTF-8'))]
application = app
httpd = make_server('', 88, app)
print("Serving on port 88...")
httpd.serve_forever()

so normally if i run a python script with this code:

x=5
exec("x+=1")
output=str(x)

at the end of this output has a value of "6" as expected

but inside a wsgi app:

x=5
exec("x+=1")
output=str(x)

now output = "5"

Why does this happen and how can I get the exec to behave like normal python (3).

Please don't let this thread turn into a debate about using exec. I want to use exec, is it possible inside wsgi?

BTW: eval() seems to works normally inside wsgi. Also: I see this running mod_wsgi in daemon and embedded mode, I also see it without mod_wsgi using python wsgiref.simple_server.

so normally if i run a python script with this code:

x=5
exec("x+=1")
output=str(x)

at the end of this output has a value of "6" as expected

but inside a wsgi app:

x=5
exec("x+=1")
output=str(x)

now output = "5"

Why does this happen and how can I get the exec to behave like normal python (3).

Please don't let this thread turn into a debate about using exec. I want to use exec, is it possible inside wsgi?

BTW: eval() seems to works normally inside wsgi. Also: I see this running mod_wsgi in daemon and embedded mode, I also see it without mod_wsgi using python wsgiref.simple_server.

here is the full code of a little wsgi app where the exec command doesnt seem to have an effect:

from wsgiref.simple_server import make_server

def app(environ, start_response):
    status = '200 OK'
    response_headers = [('content-type', 'text/html')]
    start_response(status,response_headers)
    x=5
    exec("x+=1")
    ret = str(x)
    return [bytes(ret.encode('UTF-8'))]
application = app
httpd = make_server('', 88, app)
print("Serving on port 88...")
httpd.serve_forever()
Source Link
8steve8
  • 2.3k
  • 3
  • 16
  • 17
Loading