Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from flask import Flask
- from flask import request
- import config
- import requests
- import trollius as asyncio
- app = Flask(__name__)
- def post_to_clojure():
- try:
- r = requests.post(config.uri)
- print r.raw
- except (RuntimeError, TypeError, NameError):
- print "Error while query request"
- @asyncio.coroutine
- def periodic():
- while True:
- post_to_clojure()
- yield asyncio.From(asyncio.sleep(3))
- def stop():
- task.cancel()
- @app.route('/start-timer', methods=['GET'])
- def start_timer():
- task = asyncio.Task(periodic())
- loop = asyncio.get_event_loop()
- try:
- loop.run_until_complete(task)
- except asyncio.CancelledError:
- pass
- @app.route('/stop-timer', methods=['GET'])
- def stop_timer():
- stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement