コード例 #1
0
def putter():
    log = glog.name("putter")

    log.info("putting 100000 things on queue")
    for x in xrange(100000):
        q.put(x)
        sleep()
コード例 #2
0
ファイル: nitro.py プロジェクト: 1angxi/diesel
 def _setup_the_logging_system(self):
     if not self.log:
         if self.selected_log_level is not None:
             log_level = self.selected_log_level
         else:
             log_level = self.default_log_level
         log_name = self.name or self.__class__.__name__
         self.log = log.name(log_name)
         self.log.min_level = log_level
コード例 #3
0
 def _setup_the_logging_system(self):
     if not self.log:
         if self.selected_log_level is not None:
             log_level = self.selected_log_level
         else:
             log_level = self.default_log_level
         log_name = self.name or self.__class__.__name__
         self.log = log.name(log_name)
         self.log.min_level = log_level
コード例 #4
0
def getter():
    log = glog.name("getter")
    got = 0
    while got < 25000:
        try:
            s = q.get(timeout=3)
            sleep()
        except QueueTimeout:
            log.warning("timeout before getting a value, retrying...")
            continue
        got += 1

    log.info("SUCCESS!  got all 25,000")
    cd.tick()
コード例 #5
0
from urlparse import urlparse
from flask import Request, Response
from OpenSSL import SSL

utcnow = datetime.utcnow

try:
    from http_parser.parser import HttpParser
except ImportError:
    from http_parser.pyparser import HttpParser

from diesel import receive, ConnectionClosed, send, log, Client, call, first

SERVER_TAG = 'diesel-http-server'

hlog = log.name("http-error")

HOSTNAME = os.uname()[1] # win32?

def parse_request_line(line):
    '''Given a request line, split it into
    (method, url, protocol).
    '''
    items = line.split(' ')
    items[0] = items[0].upper()
    if len(items) == 2:
        return tuple(items) + ('0.9',)
    items[1] = urllib.unquote(items[1])
    items[2] = items[2].split('/')[-1].strip()
    return tuple(items)
コード例 #6
0
ファイル: fire.py プロジェクト: 1angxi/diesel
'''Example of event firing.
'''
import time
import random
from diesel import (quickstart, quickstop, sleep, 
                    fire, wait, log, loglevels,
                    set_log_level)

set_log_level(loglevels.DEBUG)

def gunner():
    x = 1
    while True:
        fire('bam', x)
        x += 1
        sleep()

def sieged():
    t = time.time()
    while True:
        n = wait('bam')
        if n % 10000 == 0:
            log.info(str(n))
            if n == 50000:
                delt = time.time() - t
                log.debug("50,000 messages in {0:.3f}s {1:.1f}/s)", delt, 50000 / delt)
                quickstop()

log = log.name('fire-system')
quickstart(gunner, sieged)
コード例 #7
0
import random
from diesel import (quickstart, quickstop, sleep, fire, wait, log, loglevels,
                    set_log_level)

set_log_level(loglevels.DEBUG)


def gunner():
    x = 1
    while True:
        fire('bam', x)
        x += 1
        sleep()


def sieged():
    t = time.time()
    while True:
        n = wait('bam')
        if n % 10000 == 0:
            log.info(str(n))
            if n == 50000:
                delt = time.time() - t
                log.debug("50,000 messages in {0:.3f}s {1:.1f}/s)", delt,
                          50000 / delt)
                quickstop()


log = log.name('fire-system')
quickstart(gunner, sieged)
コード例 #8
0
ファイル: combined_tls.py プロジェクト: brucezhangf/diesel-1
def handle_echo(remote_addr):
    while True:
        message = until('\r\n')
        send("you said: %s" % message)


class EchoClient(Client):
    @call
    def echo(self, message):
        send(message + '\r\n')
        back = until("\r\n")
        return back


log = log.name('echo-system')


def do_echos():
    with EchoClient('localhost', 8000,
                    ssl_ctx=SSL.Context(SSL.TLSv1_METHOD)) as client:
        t = time.time()
        for x in xrange(5000):
            msg = "hello, world #%s!" % x
            echo_result = client.echo(msg)
            assert echo_result.strip() == "you said: %s" % msg
        log.info('5000 loops in {0:.2f}s', time.time() - t)
    quickstop()


quickstart(Service(handle_echo, port=8000, ssl_ctx=server_ctx), do_echos)
コード例 #9
0
ファイル: http_client.py プロジェクト: HVF/diesel
# vim:ts=4:sw=4:expandtab
'''Simple http client example.

Check out crawler.py for more advanced behaviors involving
many concurrent clients.
'''

from diesel import Application, Loop, log, quickstart, quickstop
from diesel.protocols.http import HttpClient

def req_loop():
    with HttpClient('www.jamwt.com', 80) as client:
        heads = {'Host' : 'www.jamwt.com'}
        log.info(str(client.request('GET', '/Py-TOC/', heads)))
        log.info(str(client.request('GET', '/', heads)))
    quickstop()

log = log.name('http-client')
quickstart(req_loop)
コード例 #10
0
 def __init__(self, name):
     self.__dict__['_logger'] = log.name(name)
     self.__dict__['name'] = name
コード例 #11
0
ファイル: combined.py プロジェクト: 1angxi/diesel
import time
from diesel import Service, Client, send, quickstart, quickstop
from diesel import until, call, log

def handle_echo(remote_addr):
    while True:
        message = until('\r\n')
        send("you said: %s" % message)

class EchoClient(Client):
    @call
    def echo(self, message):
        send(message + '\r\n')
        back = until("\r\n")
        return back

log = log.name('echo-system')

def do_echos():
    client = EchoClient('localhost', 8000)
    t = time.time()
    for x in xrange(5000):
        msg = "hello, world #%s!" % x
        echo_result = client.echo(msg)
        assert echo_result.strip() == "you said: %s" % msg
    log.info('5000 loops in {0:.2f}s', time.time() - t)
    quickstop()

quickstart(Service(handle_echo, port=8000), do_echos)
コード例 #12
0
ファイル: web.py プロジェクト: HVF/diesel
 def make_logger(self):
     self._dlog = log.name('diesel.web+' + self.logger_name)
コード例 #13
0
# vim:ts=4:sw=4:expandtab
'''Simple http client example.

Check out crawler.py for more advanced behaviors involving
many concurrent clients.
'''

from diesel import Application, Loop, log, quickstart, quickstop
from diesel.protocols.http import HttpClient

def req_loop():
    for path in ['/Py-TOC', '/']:
        with HttpClient('www.jamwt.com', 80) as client:
            heads = {'Host' : 'www.jamwt.com'}
            log.info(str(client.request('GET', path, heads)))
    quickstop()

log = log.name('http-client')
quickstart(req_loop)
コード例 #14
0
ファイル: crawler.py プロジェクト: 1angxi/diesel
def write_file(lpath, body):
    bytes.append(len(body))
    lpath = (lpath if not lpath.endswith('/') else (lpath + 'index.html')).lstrip('/')
    lpath = os.path.join(folder, lpath)
    ensure_dirs(lpath)
    open(lpath, 'w').write(body)

def follow_loop(lpath):
    log.info(" -> %s" % lpath)
    with conn_pool.connection as client:
        resp = client.request('GET', lpath, heads)
        write_file(lpath, resp.data)

bytes = []
count = None
log = glog.name('http-crawler')

def req_loop():
    global count

    log.info(path)
    with conn_pool.connection as client:
        resp = client.request('GET', path, heads)
    body = resp.data
    write_file(path, body)
    links = set(get_links(body))
    for l in links:
        yield l
    count = len(links) + 1

def stop():
コード例 #15
0
ファイル: web.py プロジェクト: arnaudsj/diesel
 def __init__(self, name):
     self.__dict__['_logger'] = log.name(name)
     self.__dict__['name'] = name
コード例 #16
0
ファイル: crawler.py プロジェクト: brucezhangf/diesel-1
             (lpath + 'index.html')).lstrip('/')
    lpath = os.path.join(folder, lpath)
    ensure_dirs(lpath)
    open(lpath, 'w').write(body)


def follow_loop(lpath):
    log.info(" -> %s" % lpath)
    with conn_pool.connection as client:
        resp = client.request('GET', lpath, heads)
        write_file(lpath, resp.data)


bytes = []
count = None
log = glog.name('http-crawler')


def req_loop():
    global count

    log.info(path)
    with conn_pool.connection as client:
        resp = client.request('GET', path, heads)
    body = resp.data
    write_file(path, body)
    links = set(get_links(body))
    for l in links:
        yield l
    count = len(links) + 1