This file contains hidden or 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
@gen.coroutine | |
def fetch_json(url): | |
response = yield AsyncHTTPClient().fetch(url) | |
raise gen.Return(json_decode(response.body)) |
This file contains hidden or 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
class test(dict): | |
def __init__(self): | |
self['data'] = {} | |
def __setattr__(self, name, value): | |
self['data'][name] = value | |
def __getattr__(self, name): | |
try: | |
return self['data'][name] |
This file contains hidden or 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 itertools | |
def test(data_iter, header_size): | |
h1 = itertools.islice(data_iter, header_size) | |
h2 = iter(data_iter) | |
return itertools.chain(h1, h2) |
This file contains hidden or 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
#include <uv.h> | |
#include <stdio.h> | |
#include <unistd.h> | |
uv_loop_t *loop; | |
uv_async_t async; | |
void print_progress(uv_async_t *handle, int status /*UNUSED*/) { | |
printf("%s\n", (char *)handle->data); | |
} |
This file contains hidden or 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 functools import wraps, partial | |
from period import PeriodicCallback | |
from tornado.concurrent import run_on_executor, TracebackFuture, DummyExecutor | |
import tornado.ioloop | |
import tornado.web | |
from tornado.gen import coroutine | |
class PeriodicExecutor(object): |
This file contains hidden or 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 heapq | |
def merge(*args): | |
h = [] | |
for g in args: | |
try: | |
a = g.next() | |
except StopIteration: | |
continue | |
heapq.heappush(h, (a, g)) |
This file contains hidden or 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 tornado.ioloop | |
from tornado.ioloop import IOLoop | |
import tornado.web | |
import tornado.gen | |
import tornado.httpclient | |
from resolver import CaresResolver | |
import time | |
from functools import partial | |
from period import PeriodicCallback |
This file contains hidden or 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 tornado.ioloop | |
import tornado.web | |
import tornado.gen | |
import tornado.httpclient | |
from tornado.platform.caresresolver import CaresResolver | |
import time | |
@tornado.gen.coroutine | |
def test(): | |
client = tornado.httpclient.AsyncHTTPClient() |
This file contains hidden or 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 tornado.ioloop | |
import tornado.web | |
class MainHandler(tornado.web.RequestHandler): | |
def get(self): | |
def test1(): | |
print 'test1' | |
def test2(): | |
print 'test2' | |
tornado.ioloop.IOLoop.instance().add_listener('test', test1) |
This file contains hidden or 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 tornado.ioloop | |
import tornado.web | |
import tasks | |
class AppHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write("test app") | |
class MainHandler(tornado.web.RequestHandler): |