A response to Preetam Jinka's nice little Go demo.
Similar basic HTTP server using Gevent/Python
from gevent import pywsgi
import md5
def md5_body(environ, start_response):
md5Hash = md5.new()
#!/usr/bin/env python | |
import dpkt, pcap, socket | |
from ipaddr import IPv4Address, IPv6Address | |
import syslog | |
class HTTPRequest(): | |
def __init__(self, host, uri, ip = None, user_agent = None): | |
self.uri = uri | |
self.user_agent = user_agent | |
self.host = host |
# Espresso Pattern | |
# This shows how to capture data using a pub-sub proxy | |
# | |
import time | |
from random import randint | |
from string import uppercase | |
from threading import Thread |
""" | |
An XPUB/XSUB broker that forwards subscriptions | |
""" | |
import os | |
import string | |
import sys | |
import time | |
from random import randint | |
from threading import Thread |
# use with: logging.config.dictConfig(yaml.load(open('logging.yaml', 'r'))) | |
# Formatters detailed here: http://docs.python.org/2/library/logging.html#logrecord-attributes | |
version: 1 | |
formatters: | |
simple: | |
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
detail: | |
format: '%(asctime)s - %(levelname)s - File: %(filename)s - %(funcName)s() - Line: %(lineno)d - %(message)s' |
A response to Preetam Jinka's nice little Go demo.
Similar basic HTTP server using Gevent/Python
from gevent import pywsgi
import md5
def md5_body(environ, start_response):
md5Hash = md5.new()
import gevent, gevent.event | |
import threading, Queue, collections, time, functools | |
def _threads_poller_f(): | |
while _OsThread._threads_count: | |
try: | |
t, rv, isexc = _OsThread._threads_results.get_nowait() | |
except Queue.Empty: | |
gevent.sleep() | |
else: |
import sys | |
from gevent import server | |
from gevent.monkey import patch_all; patch_all() | |
from multiprocessing import Process, current_process, cpu_count | |
def note(format, *args): | |
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args)) | |
def echo(socket, address): |
#!/usr/bin/env python | |
""" | |
Gevent examples. | |
""" | |
import json | |
import gevent |
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# Author: Yuande Liu <miraclecome (at) gmail.com> | |
from __future__ import print_function, division | |
from gevent import monkey; monkey.patch_all() | |
import gevent | |
import time |
#!/usr/bin/env python | |
"""Resolve hostnames concurrently, exit after 60 seconds. | |
Under the hood, this might use an asynchronous resolver based on | |
c-ares (the default) or thread-pool-based resolver. | |
You can choose between resolvers using GEVENT_RESOLVER environment | |
variable. To enable threading resolver: | |
GEVENT_RESOLVER=thread python dns_mass_resolve.py |