Skip to content

Instantly share code, notes, and snippets.

Frame 45647: 174 bytes on wire (1392 bits), 174 bytes captured (1392 bits)
Ethernet II, Src: 42:01:0a:80:00:01 (42:01:0a:80:00:01), Dst: 42:01:0a:80:00:1c (42:01:0a:80:00:1c)
Internet Protocol Version 4, Src: 10.128.0.14, Dst: 10.128.0.28
Transmission Control Protocol, Src Port: 41090, Dst Port: 26257, Seq: 13781, Ack: 9845, Len: 108
PostgreSQL
Type: Parse
Length: 79
Statement:
Query: SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE
Parameters: 0
@bdarnell
bdarnell / gist:8553378
Created January 22, 2014 04:12
Example for StaticFileHandler.get_absolute_path
# 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))
@bdarnell
bdarnell / gist:8641880
Created January 27, 2014 01:24
Unix socket HTTP client via custom resolver
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):
@bdarnell
bdarnell / fdserver.py
Created July 9, 2011 20:41
Demonstration of sharing file descriptors across processes
#!/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).
@bdarnell
bdarnell / tornado_tulip.py
Created January 20, 2013 22:31
Proof of concept tornado/tulip integration
"""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:
@bdarnell
bdarnell / README.md
Created September 21, 2015 17:41
Scripts for running multi-node cockroachdb cluster

Run make build in the cockroach repo and copy the binary to ./bin/cockroach (relative to wherever you have downloaded these scripts).

Run init.sh once, then run start.sh 1, start.sh 2, and start.sh 3 in separate terminals. After that, run shell.sh to start a SQL shell.

To wipe everything and start over, kill all the processes started by start.sh and delete the node* directories.

@bdarnell
bdarnell / streaming.py
Created January 11, 2015 21:23
Demo of streaming requests with Tornado
"""Demo of streaming requests with Tornado.
This script features a client using AsyncHTTPClient's body_producer
feature to slowly produce a large request body, and two server
handlers to receive this body (one is a proxy that forwards to the
other, also using body_producer).
It also demonstrates flow control: if --client_delay is smaller than
--server_delay, the client will eventually be suspended to allow the
server to catch up. You can see this in the logs, as the "client
@bdarnell
bdarnell / debug_log_filter.py
Created July 15, 2012 20:30
Python logging filter for per-module debug logging
# 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
@bdarnell
bdarnell / django_tornado_handler.py
Created October 29, 2010 18:59
django_tornado_handler.py
# 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