Skip to content

Instantly share code, notes, and snippets.

import subprocess
import select
from threading import Thread
from cStringIO import StringIO
def read_stream(stream, output_stream, log_func):
while True:
r, w, x = select.select([stream.fileno()], [], [], 1.0)
if not r:
#!/usr/bin/env python
"""
Modifiy from urllib3 benchmark
https://raw.github.com/shazow/urllib3/master/test/benchmark.py
Really simple rudimentary benchmark to compare ConnectionPool versus standard
urllib to demonstrate the usefulness of connection re-using.
"""
from __future__ import print_function
@yhchan
yhchan / thread-subprocess.py
Last active December 17, 2015 13:39
subprocess with reading stdout and stderr in threads
import select
import subprocess
from threading import Thread
from cStringIO import StringIO
import logging
logger = logging.getLogger(__name__)
@yhchan
yhchan / gist:5410941
Created April 18, 2013 07:45
python defaultdict
from collections import defaultdict
class _MissingDictionary(defaultdict):
def __missing__(self, key):
return defaultdict(_MissingDictionary)
configs = defaultdict(_MissingDictionary)
@yhchan
yhchan / gist:1378486
Created November 19, 2011 05:32
openssl-dev for i586-mingw32
$ tar zxvf openssl-1.0.0e.tar.gz
$ cd openssl-1.0.0e/
$ ./Configure --prefix=/usr/i586-mingw32msvc mingw
$ sed -i "s/crypto ssl engines apps test tools/crypto ssl engines/" Makefile
$ make CC=i586-mingw32msvc-gcc RANLIB=i586-mingw32msvc-ranlib
$ sudo make install
@yhchan
yhchan / node-devel-0.3.2.log.1
Created December 27, 2010 05:55
node-devel-0.3.2.log.1
===> Building for node-devel-0.3.2
Waf: Entering directory `/usr/ports/www/node-devel/work/node-v0.3.2/build'
[51/73] libv8.a: deps/v8/SConstruct -> build/default/libv8.a
/usr/local/bin/python2.7 "/usr/ports/www/node-devel/work/node-v0.3.2/tools/scons/scons.py" -j 1 -C "/usr/ports/www/node-devel/work/node-v0.3.2/build/default/" -Y "/usr/ports/www/node-devel/work/node-v0.3.2/deps/v8" visibility=default mode=release arch=x64 library=static snapshot=on
scons: Reading SConscript files ...
scons: warning: Ignoring missing SConscript 'obj/test/release/SConscript'
File "/usr/ports/www/node-devel/work/node-v0.3.2/deps/v8/SConstruct", line 1102, in BuildSpecific
scons: done reading SConscript files.
scons: Building targets ...
@yhchan
yhchan / node-devel-0.3.2.log
Created December 27, 2010 05:41
node-devel-0.3.2.log
===> License check disabled, port has not defined LICENSE
=> node-v0.3.2.tar.gz doesn't seem to exist in /usr/ports/distfiles/.
=> Attempting to fetch from ftp://ftp.tw.freebsd.org/pub/FreeBSD/distfiles/.
fetch: ftp://ftp.tw.freebsd.org/pub/FreeBSD/distfiles/node-v0.3.2.tar.gz: File unavailable (e.g., file not found, no access)
=> Attempting to fetch from ftp://ftp5.tw.freebsd.org/pub/FreeBSD/ports/distfiles/.
fetch: ftp://ftp5.tw.freebsd.org/pub/FreeBSD/ports/distfiles/node-v0.3.2.tar.gz: File unavailable (e.g., file not found, no access)
=> Attempting to fetch from http://nodejs.org/dist/.
node-v0.3.2.tar.gz 4329 kB 823 kBps
===> Extracting for node-devel-0.3.2
=> SHA256 Checksum OK for node-v0.3.2.tar.gz.