Skip to content

Instantly share code, notes, and snippets.

@saghul
saghul / ts.py
Created November 27, 2013 08:27
import erequests
import os
HTTPBIN_URL = os.environ.get('HTTPBIN_URL', 'http://httpbin.org/')
def httpbin(*suffix):
"""Returns url for HTTPBIN resource."""
return HTTPBIN_URL + '/'.join(suffix)
@saghul
saghul / tj.py
Created November 26, 2013 21:41
import erequests
URLS = ['http://httpbin.org/get?p=%s' % i for i in range(5)]
result = {}
def hook(r, **kwargs):
print "XXX"
@saghul
saghul / t.py
Created November 21, 2013 11:25
import asyncio
import time
loop = asyncio.get_event_loop()
def some_work():
time.sleep(1)
import pyuv
import threading
import time
def cb(handle):
print "x"
def run():
import os
def rls(path):
for dirname, dirnames, filenames in os.walk(path):
# directories first
for subdirname in dirnames:
yield os.path.join(dirname, subdirname)
# files next
for filename in filenames:
@saghul
saghul / app.py
Created July 9, 2013 22:28
WSGI + WebSocket + static files Twisted example
import os
from autobahn.resource import WebSocketResource, WSGIRootResource
from autobahn.websocket import WebSocketServerFactory, WebSocketServerProtocol
from flask import Flask, render_template
from twisted.application import internet, service
from twisted.internet import reactor
from twisted.python.threadpool import ThreadPool
from twisted.web.server import Site
$ tox -c tox.ini.saghul -e py33-caresresolver -vv
/usr/local/bin/tox:5: UserWarning: Module pkg_resources was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/pkg_resources.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import load_entry_point
/usr/local/bin/tox:5: UserWarning: Module site was already imported from /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site.pyc, but /Library/Python/2.6/site-packages is being added to sys.path
from pkg_resources import load_entry_point
using tox.ini: /Users/saghul/src/tornado/tox.ini.saghul
using tox-1.4.2 from /Library/Python/2.6/site-packages/tox/__init__.pyc
GLOB start: packaging
GLOB sdist-make: /Users/saghul/src/tornado/setup.py
/Users/saghul/src/tornado$ /usr/bin/python /Users/saghul/src/tornado/setup.py sdist --formats=zip --dist-dir /Users/saghul/src/tornado/.tox/dist >/Users/saghul/src/tornado/.tox/log/tox-0.log
@saghul
saghul / output
Last active December 12, 2015 10:19
$ python t.py
ping
ping
ping
ping
pingping
stop1
Task(<_foo>)<PENDING, [<function _raise_stop_error at 0x1010ef440>]>False
ping
pingping
@saghul
saghul / t.py
Created February 11, 2013 12:13
import rose
from tulip import events
from tulip import tasks
#events.set_event_loop_policy(rose.EventLoopPolicy())
reactor = events.get_event_loop()
def _foo():