Skip to content

Instantly share code, notes, and snippets.

@akhenakh
akhenakh / gist:5825280
Last active April 21, 2016 16:12
Decorator for Tornado function, that will log all exception in MongodB, implies all handlers have a self.db properties connected to mongo
def log_exception(view_func):
""" log exception decorator for a view,
"""
def _decorator(self, *args, **kwargs):
try:
response = view_func(self, *args, **kwargs)
except:
if self.settings['debug']:
raise
tb = traceback.format_exc()
@jamescasbon
jamescasbon / backbonehandler.py
Created April 18, 2012 20:02
Backbone.js handler for tornado and mongodb backed handler
"""
Backbone.js handler and mongodb based handler for Tornado.
`BackboneHandler` handles the sync protocol for Backbone.js. Inherit
from the class and implement the model methods:
* create_model
* update_model
* get_model
* delete_model
* get_collection
@methane
methane / gist:2185380
Created March 24, 2012 17:28
Tornado Example: Delegating an blocking task to a worker thread pool from an asynchronous request handler
from time import sleep
from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.web import Application, asynchronous, RequestHandler
from multiprocessing.pool import ThreadPool
_workers = ThreadPool(10)
def run_background(func, callback, args=(), kwds={}):
def _callback(result):
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.