Beispiel #1
0
def main():
    parser = ArgumentParser(description='Serve Durus databases via TCP/IP')
    parser.add_argument(
        'path', type=str,
        help='Path containing databases.')
    parser.add_argument(
        '--host', type=str, default=DEFAULT_HOST,
        help='Interface to serve on.')
    parser.add_argument(
        '--port', type=int, default=DEFAULT_PORT,
        help='Port to serve on.')
    # parser.add_argument(
    #     '--gcbytes', type=int, default=DEFAULT_GCBYTES,
    #     help='Number of bytes to transfer between packing.')
    parser.add_argument(
        '--loglevel', type=int, default=20,
        help='Logging level.')
    args = parser.parse_args()
    logger.setLevel(args.loglevel)
    scheduler = Scheduler()
    server = Server(
        scheduler=scheduler,
        path=args.path,
        host=args.host,
        port=args.port,
        )
    scheduler.add(server.dispatch)
    scheduler.run()
Beispiel #2
0
from cogen.core.coroutines import coroutine
from cogen.core.schedulers import Scheduler
from cogen.core import events

@coroutine
def foo():
    print 'foo'
    result = yield bar("ham")
    print result

@coroutine
def bar(what):
    print 'bar'
    raise StopIteration("spam, %s and eggs" % what)

sched = Scheduler()
sched.add(foo)
sched.run()
import sys
import time
import stackless

from cogen.core.schedulers import Scheduler
from cogen.core.coroutines import coroutine
from cogen.core import events
@coroutine
def mycoro():
    while 1:
        yield events.Sleep(1)
        print '#'

sched = Scheduler()
sched.add(mycoro)
sched_iter = sched.iter_run()

def tasklet():

    while True:
        # complicated operation with side-effects
        print '.'
        time.sleep(0.1)

        # run a cogen loop
        sched_iter.next()

# start the simple tasklet
stackless.tasklet(tasklet)()

# start the stackless scheduler
Beispiel #4
0
from cogen.core.coroutines import coroutine
from cogen.core.schedulers import Scheduler
from cogen.core.sockets import Socket
from cogen.core.proactors import has_select

@coroutine
def somecoroutine():
    mysocket = Socket() # cogen's socket wrapper
    yield mysocket.connect(('www.google.com',80))
    fh = mysocket.makefile()
    yield mysocket.sendall("GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n")
    #~ result = yield fh.readline()
    result = yield mysocket.recv(10240)
    print result

sched = Scheduler(proactor=has_select())
#~ sched = Scheduler()
sched.add(somecoroutine)
sched.run() # this is the main loop
Beispiel #5
0
        "Return a CoroutineInstance instance"
        inst = self.constructor(self.wrapped_func, *args, **kwargs)
        inst.debug = True
        return inst

debug_corolet = DebugCorolet

if __name__ == "__main__":
    from cogen.core.events import Sleep
    from cogen.core.schedulers import Scheduler

    def bar():
        yield_(events.Sleep(1))
        print 2
        raise Exception('BOOOO!!!')

    def foo():
        bar()

    @corolet
    def some_func():
        "blablalbla"
        print 1
        foo()
        print 3


    m = Scheduler()
    m.add(some_func)
    m.run()