Skip to content

Instantly share code, notes, and snippets.

View smokey42's full-sized avatar

Christoph Rauch smokey42

  • Germany
View GitHub Profile
@shazow
shazow / meta.py
Created December 17, 2009 00:59
BaseModel object for SQLAlchemy declarative object abstractions (with query statistics tracking and JSON decoder).
"""SQLAlchemy Metadata and Session object"""
from sqlalchemy import MetaData
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.orm.session import Session as SessionBase
from sqlalchemy.interfaces import ConnectionProxy
from datetime import datetime
import time
__all__ = ['Session', 'metadata', 'BaseModel']
class BaseHandler(RequestHandler):
# .... other stuff ....
def _handle_request_exception(self, e):
RequestHandler._handle_request_exception(self,e)
import pdb
pdb.post_mortem()
def bp():
@jparise
jparise / gist:3428652
Created August 22, 2012 19:39
Tornado Graceful Shutdown
def shutdown(graceful=True):
"""Shut down the application.
If a graceful stop is requested, waits for all of the IO loop's
handlers to finish before shutting down the rest of the process.
We impose a 10 second timeout.
"""
ioloop = tornado.ioloop.IOLoop.instance()
def final_stop():
@lucasrcosta
lucasrcosta / tornado_handler_thread_decorator.py
Last active February 20, 2019 08:51
Tornado Handler Thread Decorator
from concurrent.futures import ThreadPoolExecutor
from datetime import timedelta
from tornado import gen
from tornado.concurrent import run_on_executor
THREADPOOL_MAX_WORKERS = 10
THREADPOOL_TIMEOUT_SECS = 30
def onthread(function):