This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tools/third_party/dowser/__init__.py b/tools/third_party/dowser/__init__.py | |
index fa562b1..d716a2a 100644 | |
--- a/tools/third_party/dowser/__init__.py | |
+++ b/tools/third_party/dowser/__init__.py | |
@@ -54,6 +54,7 @@ class Root: | |
if cherrypy.__version__ >= '3.1': | |
cherrypy.engine.subscribe('exit', self.stop) | |
self.runthread = threading.Thread(target=self.start) | |
+ self.runthread.daemon = True | |
self.runthread.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NOTE: This code was extracted from a larger class and has not been | |
# tested in this form. Caveat emptor. | |
import django.conf | |
import django.contrib.auth | |
import django.core.handlers.wsgi | |
import django.db | |
import django.utils.importlib | |
import httplib | |
import json | |
import logging |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# simple benchmark comparing with and try statements | |
import contextlib | |
import timeit | |
def work_pass(): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import functools | |
import logging | |
import sys | |
class ResultCollector(object): | |
'''Like a BarrierCallback, but saves results passed to the callback. | |
>>> rc = ResultCollector() | |
>>> cb_foo = rc.get_callback('foo') | |
>>> cb_bar = rc.get_callback('bar') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""This is a demonstration of sharing file descriptors across processes. | |
It uses Tornado (need a recent post-2.0 version from github) and the | |
multiprocessing module (from python 2.6+). To run it, start one copy | |
of fdserver.py and one or more copies of testserver.py (in different | |
terminals, or backgrounded, etc). Fetch http://localhost:8000 and | |
you'll see the requests getting answered by different processes (it's | |
normal for several requests to go to the same process under light | |
load, but under heavier load it tends to even out). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A simple log filter to turn debug logging on and off on a per-module | |
# basis, when using tornado-style logging. Note that this works based | |
# on the module where the log statement occurs, not the name passed to | |
# logging.getLogger(), so it works even with libraries write directly | |
# to the root logger. | |
# | |
# One drawback to this approach (as opposed to using distinct | |
# per-module loggers and setting their levels appropriately) is that | |
# logger.isEnabledFor(DEBUG) will return true even when called from a | |
# module where debug output is not enabled, so modules that perform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Proof of concept tornado/tulip integration. | |
Works with the current development branch of both projects as of | |
Jan 20. Current status: The tornado test suite passes cleanly | |
on a tulip-backed IOLoop. The tornado-backed event loop for tulip | |
supports the core call_later and add_reader method families, but not | |
the higher-level networking methods. | |
To run the tornado test suite on tulip, make sure both projects | |
and this file are on your python path and run: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For http://stackoverflow.com/questions/21248222/how-can-tornado-serve-a-single-static-file-at-an-arbitrary-location/21248691?noredirect=1#comment32053685_21248691 | |
class MyFileHandler(StaticFileHandler): | |
def initialize(self, file_mapping, **kwargs): | |
self.file_mapping = file_mapping | |
super(MyFileHandler, self).initialize(**kwargs) | |
@classmethod | |
def get_absolute_path(cls, root, path): | |
return StaticFileHandler.get_absolute_path(root, self.file_mapping.get(path, path)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
from tornado.concurrent import TracebackFuture, return_future | |
from tornado import gen | |
from tornado.httpclient import AsyncHTTPClient | |
from tornado.httpserver import HTTPServer | |
from tornado.ioloop import IOLoop | |
from tornado.netutil import bind_unix_socket, Resolver | |
from tornado.web import RequestHandler, Application | |
class HelloHandler(RequestHandler): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tornado.concurrent import Future | |
from tornado import gen | |
from somewhere import parse_headers | |
class HTTPReader(object): | |
def __init__(self, stream): | |
self.stream = stream | |
self.header_future = Future() | |
self.chunk_future = None | |
self.read_ready = Future() |
OlderNewer