Skip to content

Instantly share code, notes, and snippets.

'''
A Non blocking task scheduler and executor implemented using co routines and Tornado
Torando components acts as a non blocking listener and the 2 co routines scheduler and task exectutor
'''
import tornado.ioloop
import tornado.web
import tornado.httpserver
import tornado.gen
import time
@sunilmallya
sunilmallya / gist:6299539
Created August 21, 2013 20:09
tornado multiprocessing async httpclient
#Pseduo python code
class HttpDownload(object):
def __init__(self,job,ioloop):
self.ioloop = ioloop
#create async http request
self.http_client = tornado.httpclient.AsyncHTTPClient()
self.http_client.fetch(self.req, self.async_callback)
def async_callback(self,reponse):
@sunilmallya
sunilmallya / gist:4671033
Created January 30, 2013 05:55
dumpObject
"""
Dump python object
@author: Not sure, had this code snippet, happy to attribute to who wrote this, saving for personal use
"""
def printDict(di, format="%-25s %s"):
for (key, val) in di.items():
print format % (str(key)+':', val)
def dumpObj(obj, maxlen=77, lindent=24, maxspew=600):
"""Print a nicely formatted overview of an object.
@sunilmallya
sunilmallya / parent_child_mp_reduction
Last active August 27, 2022 05:03
multiprocessing.reduction socket server with parent processing passing connections to client after accepting connections
#!/usr/bin/env python
"""
@author Sunil Mallya
Sample code to show a parent - child like process communication model where parent listens on a port and passes the pickled file descriptor
to the child process to read the bytes off the socket. The communication in this snippet is via a Queue which is thread/process safe
Just to be clear, the parent process is still accepting the connection and we are sending a live fd to the child
"""
import os
import sys