Skip to content

Instantly share code, notes, and snippets.

@DonnchadhCameron
DonnchadhCameron / sub.py
Created April 21, 2016 16:08 — forked from JobsDong/sub.py
使用tornado将命令行操作包装成异步
#!/usr/bin/python2.7
#-*- coding=utf-8 -*-
import shlex
import subprocess
from tornado.gen import coroutine, Task, Return
from tornado.process import Subprocess
from tornado.ioloop import IOLoop
@coroutine
"""
This is a simple example of WebSocket + Tornado + Redis Pub/Sub usage.
Do not forget to replace YOURSERVER by the correct value.
Keep in mind that you need the *very latest* version of your web browser.
You also need to add Jacob Kristhammar's websocket implementation to Tornado:
Grab it here:
http://gist.github.com/526746
Or clone my fork of Tornado with websocket included:
http://github.com/pelletier/tornado
Oh and the Pub/Sub protocol is only available in Redis 2.0.0:
@DonnchadhCameron
DonnchadhCameron / async_psycopg2.py
Created April 21, 2016 16:01 — forked from FSX/async_psycopg2.py
A module for asynchronous PostgreSQL queries in Tornado.
#!/usr/bin/env python
__author__ = 'Frank Smit <[email protected]>'
__version__ = '0.1.0'
import functools
import psycopg2
from tornado.ioloop import IOLoop, PeriodicCallback
@DonnchadhCameron
DonnchadhCameron / app.py
Created April 21, 2016 15:55 — forked from ayang/app.py
Tornado session manager use redis
class Application(tornado.web.Application):
def __init__(self):
tornado.web.Application.__init__(self, handlers, **settings)
self.db_session = db_session
self.redis = redis.StrictRedis()
self.session_store = RedisSessionStore(self.redis)
class BaseHandler(tornado.web.RequestHandler):
import re
import itertools
import logging
from apscheduler.triggers.cron import CronTrigger
from tornado.ioloop import IOLoop
from datetime import datetime
class CronCallback(object):
"""Schedules the given callback to be called periodically.