I am new to ascynio python function and I have a server that processes websocket requests from a browser. Here is a simplified version of how this works:
@asyncio.coroutine
def web_client_connected(self, websocket):
self.web_client_socket = websocket
while True:
request = yield from self.web_client_socket.recv()
json_val = process_request(request)
yield from self.socket_queue.put(json_val)
@asyncio.coroutine
def push_from_web_client_json_queue(self):
while True:
json_val = yield from self.socket_queue.get()
yield from self.web_client_socket.send(json_val)
You have one loop that looks for web socket requests coming from the client. When it gets one, it processes it and puts the value in the queue. Another loop searches for values in this queue, and when it finds one, it sends the processed value back to the web socket. Pretty straight forward and it works.
What I want to do is enter a timer. When requests arrive and are processed, instead of immediately responding to the queue, I want to start the timer for 1 minute. When the timer is over, I want to queue the response.
I tried something like:
@asyncio.coroutine
def web_client_connected(self, websocket):
self.web_client_socket = websocket
while True:
request = yield from self.web_client_socket.recv()
json_val = process_request(request)
t = threading.Timer(60, self.timer_done, json_val)
t.start()
@asyncio.coroutine
def timer_done(self, args):
yield from self.socket_queue.put(args)
. timer_done . @asyncio.coroutine yield from, timer_done , self.socket_queue.put(args) .
, . ?