tornado

Raspberry Pi camera. Out of resources

自闭症网瘾萝莉.ら 提交于 2019-12-12 03:34:06
问题 Trying to launch my camera with motion sensor. Works fine like this: import RPi.GPIO as GPIO import time import picamera import datetime import os def getFileName(): return datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S.h264") pin = 4 GPIO.setmode(GPIO.BCM) GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) prevState = False currState = False camera = picamera.PiCamera() while True: time.sleep(0.1) prevState = currState currState = GPIO.input(pin) if currState != prevState: newState =

tornado one handler blocks for another

我与影子孤独终老i 提交于 2019-12-12 03:17:19
问题 Using python/tornado I wanted to set up a little "trampoline" server that allows two devices to communicate with each other in a RESTish manner. There's probably vastly superior/simpler "off the shelf" ways to do this. I'd welcome those suggestions, but I still feel it would be educational to figure out how to do my own using tornado. Basically, the idea was that I would have the device in the role of server doing a longpoll with a GET. The client device would POST to the server, at which

Tornado - mount Bottle app

淺唱寂寞╮ 提交于 2019-12-12 02:54:36
问题 How do you mount Bottle app in Tornado server? Here is my code 回答1: bottle.default_app() returns a WSGI callable: if __name__ == "__main__": bottle_app = bottle.default_app() bottle_handler = tornado.wsgi.WSGIContainer(bottle_app) HTTPServer(Application([(r"/ws", WSHandler), (r"/css/(.*)", StaticFileHandler, {"path": "./css/"}), (r"/js/(.*)", StaticFileHandler, {"path": "./js/"}), (r"/img/(.*)", StaticFileHandler, {"path": "./img/"}), ("/(.*)", bottle_handler)]) ).listen(1024) IOLoop.instance

NameError, global not defined when using try,except

让人想犯罪 __ 提交于 2019-12-12 01:29:21
问题 Edit: Ignore this, I figured it out about 3 seconds after posting this but can't delete it =( I have this try, except code for working with RackSpace cloudfiles try: cacheobject = cachecontainer.get_object('file.jpg') except NoSuchObject as objectname: raise tornado.web.HTTPError(404) If 'file.jpg' is not found, the exception 'NoSuchObject' is raised. When I run this code I get the error except NoSuchObject as objectname: NameError: global name 'NoSuchObject' is not defined I tried putting

how to send json header via python tornado in a websocket?

浪尽此生 提交于 2019-12-11 21:01:59
问题 #!C:/Python27/python.exe -u import tornado import tornado.websocket import tornado.wsgi import tornado.web import tornado.httpserver import tornado.tcpserver import json from py2neo import neo4j, cypher graph_db = neo4j.GraphDatabaseService() class request(tornado.web.RequestHandler): def sr(): self.set_header('Content-type','application/json') class ChatWebSocket(tornado.websocket.WebSocketHandler): clients = [] def open(self): ChatWebSocket.clients.append(self) def on_message(self, message)

Get client port number using tornado using WebSockets

烈酒焚心 提交于 2019-12-11 20:37:52
问题 I can get client ip: self.request.remote_ip I can also get client port number from RequestHandler: self.request.connection.stream.socket.getpeername()[1] (thanks to this) But what about client port number from WebSocket? I can't find anything on how to do this in the docs. I have had a long look through the source but still can't figure out where it is. 回答1: As I said in How to get the client port in RequestHandler?, the first question is why do you want this? In a websocket handler, the

How to logging with timed rotate file handler in Tornado?

给你一囗甜甜゛ 提交于 2019-12-11 20:33:43
问题 I've asked a question (how to manage nohup.out file in Tornado) about how to handle nohup.out file automatically when running a Tornado web service. And I decided to use the logging module of Tornado to write my log files. I read about the documents of Tornado. The logging module it provides doesn't have the TimedRotatingFileHandler , I still cannot manage the logging files as dates. So I want to know how to use TimedRotatingFileHandler in the logging module of Tonado? 回答1: I have rotating

How to wait for the calling of request.finish() in Python/Tornado

心不动则不痛 提交于 2019-12-11 19:36:57
问题 In my python file I have two handler classes: MainHandler(tornado.web.RequestHandler) and WebSocketHandler(tornado.web.WebSocketHandler). In the MainHandler class I do the following code in the get method: class MainHandler(tornado.web.RequestHandler): #some code def get(self): #some code mainHandler_dict[chan] = self await self.finish() #line of code that would do the waiting somehow So I store the request in a global dictionary so I can call request.write() and request.finish() in the on

tornado v6 seems to have dropped tornado.web.asynchronous coroutine. any different way of fixing this in code?

旧巷老猫 提交于 2019-12-11 19:16:13
问题 Migrated torando v5.1 to v6. but asynchronous coroutine seems to have removed. Any suggestions for its fix? Migrating the project from 2.7 to 3.6, at the same time moving tornado framework from v5.1 to v6.0.2 due to the bug suggested in this [Python code for DynamoDB query is working on v3.6 but not working in python 2.7 strackoverflow thread. After installing v6 tornado it is breaking with below error. Python3 xxxx.py Traceback (most recent call last): File "XXXX.py", line 200, in <module>

Hitting multiple APIs at once, tornado and python

倖福魔咒の 提交于 2019-12-11 16:59:23
问题 I'm trying to make an API that will collect responses from several other API's and combine the results into one response. I want to sent the get requests asynchronously so that it runs faster, but even though I'm using coroutines and yielding, my code still seems to be making each request one at a time. Wondering if maybe it's because I'm using the requests library instead of tornado's AsyncHTTPClient, or because I'm calling self.path_get inside of a loop, or because I'm storing results in an