Globale Variables with Bottlpy (in background)
<p>i need to use global variables in my program with either flask or bottle running as a webservice. so far im using bottle as a thread with a snippet i found here: <a href="http://stackoverflow.com/questions/13021762/starting-python-bottle-in-a-thread-process-and-another-daemon-next-to-it">Starting python bottle in a thread/Process and another daemon next to it</a></p>

<p>i basically want to go to localhost:8080/hello to increase the global variable test by one:</p>

<pre><code>#!/usr/bin/env python
from bottle import route, run
from multiprocessing import Process

@route('/hello')
def hello():
    global test
    test = test + 1
    return test

def main():
    global test
    test = 0

    t = Process(target=bottle.run(host='0.0.0.0', port=8080))
    t.daemon = True
    t.start()

    while(True)
        print test
        time.sleep(0.5)     

if __name__ == "__main__":
    main()
</code></pre>

<p>if i go to localhost:8080/hello with my browser i get:
    Error 500: Internal Server Error - Unhandled Exception</p>

<p>i cant see the exception tho, even with</p>

<pre><code>try
    global test
    test = test + 1
    return test
except Exception e
    print e
</code></pre>

<p>You're returning an <code>int</code> from <code>hello</code>, but you need to return an iterable (of strings).</p>

<p>Tip: add <code>debug=True</code> to your call to <code>run</code> to get better error info in your response.</p>

<p><code>t = Process(target=run(host='0.0.0.0', port=8080, debug=True))</code></p>

python bottle