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 tornado.web | |
from multiprocessing import Pipe | |
from _multiprocessing import Connection | |
class MultiprocessApplication(tornado.web.Application): | |
def __init__(self, *args, **kwargs): | |
self._conn_main_recv, self._conn_main_send = Pipe() | |
tornado.web.Application.__init__(self, *args, **kwargs) | |
def setup(self, ioloop, is_main_process): |
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 tornado.web | |
from multiprocessing import Pipe | |
from _multiprocessing import Connection | |
class MultiprocessApplication(tornado.web.Application): | |
def __init__(self, *args, **kwargs): | |
self._conn_main_recv, self._conn_main_send = Pipe() | |
tornado.web.Application.__init__(self, *args, **kwargs) | |
def setup(self, ioloop, is_main_process): |
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 os | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.web | |
from multiprocessing import Pipe | |
class HelloHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write(self.application.communicate('hello world')) |
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
> python -m cProfile -s time client.py | |
3806027 function calls (3805761 primitive calls) in 39.336 CPU seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
100000 21.909 0.000 37.780 0.000 {method 'recv_multipart' of 'zmq._zmq.Socket' objects} | |
900002 8.073 0.000 8.920 0.000 threading.py:179(__init__) | |
900002 3.256 0.000 12.176 0.000 threading.py:174(Condition) | |
300000 3.061 0.000 15.871 0.000 Queue.py:22(__init__) |
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 sys | |
import os, os.path | |
sys.path.insert(0, os.getcwd()) | |
import zmq | |
addr = 'inproc://tmp1' | |
msg = '0' | |
copy = True | |
sw = zmq.Stopwatch() | |
cycles = int(sys.argv[1]) |
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 os, sys, socket, passfd | |
import tornado.httpserver | |
import tornado.ioloop | |
import tornado.web | |
import time | |
class HelloHandler(tornado.web.RequestHandler): | |
def get(self): | |
self.write('hello from pid: %s' % os.getpid()) |
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
class What(object): | |
def __init__(self, arg={}): | |
self.arg = arg | |
assert not len(self.arg) | |
arg[1] = 2 | |
What() | |
# Whoops... arg is a mutable object |
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
def parse(data): | |
char = data.pop(0) | |
if char == '[': | |
return parse_list(data) | |
elif char == '{': | |
return parse_object(data) | |
elif '0' <= char <= '9': | |
return parse_int(char, data) | |
elif char in 'tfn': |
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 | |
main = lambda view, port, host='0.0.0.0', recvlen=4096, recvtimeout=0.0: ( | |
(lambda sys, socket, itertools, urllib, re, cStringIO, pprint, datetime, types, select, traceback, BaseHTTPServer: | |
(lambda _try, recursive: | |
(lambda HttpRequest, HttpResponse: | |
(lambda conn2buf, serverloop, log_hit, errorview: | |
(lambda sock, handler: | |
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) or |
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 Data.List (partition) | |
sortByOther :: String -> String -> String | |
sortByOther [] _ = [] | |
sortByOther (x:xs) ins = matches ++ sortByOther xs rejects | |
where (matches, rejects) = partition (==x) ins | |
main = putStrLn $ sortByOther "abcd" "ccbbaae" |
OlderNewer