squeaky-pl / japronto

Screaming-fast Python 3.5+ HTTP toolkit integrated with pipelining HTTP server based on uvloop and picohttpparser.
MIT License
8.61k stars 581 forks source link

Global variable update problem #138

Closed alikopasa closed 5 years ago

alikopasa commented 5 years ago

Hello,

With below code updateGlobalTime is updating globaltime every second. But when i request url /time in hello def globaltime is not updating.

Could anyone help me for that please?

Best Regards

from japronto import Application
import sys,os,time
import threading
import asyncio

globaltime=1
port=8080

app = Application()

def updateGlobalTime():
    global globaltime
    globaltime = int(round(time.time() * 1000))

    print("globaltime",globaltime)
    threading.Timer(1, updateGlobalTime).start()

updateGlobalTime()

def hello(request):
    global globaltime
    timefromhello = int(round(time.time() * 1000))
    return request.Response(json={'timefromhello': timefromhello, 'globaltime': globaltime})

app.router.add_route('/time', hello)
app.run(port=port,debug=True)
pulord commented 5 years ago

HI @alikopasa I get the same problem. How can i solve this?