Exemple #1
0
def main(timeout = None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        Tasklet.later(timeout, quit, name = 'unittest_timeout')(EXIT_CODE_TIMEOUT)
        
    dispatch(unittest.main)
Exemple #2
0
def serve(endpoint = ('0.0.0.0', 8080), controllers = []):
    """a convenience method to quickly start an application for testing"""
    application = Application()
    for controller in controllers:
        application.add_controller(controller)
    application.configure()
    application.serve(endpoint)
    
    from concurrence import dispatch
    dispatch()
Exemple #3
0
def serve(endpoint=('0.0.0.0', 8080), controllers=[]):
    """a convenience method to quickly start an application for testing"""
    application = Application()
    for controller in controllers:
        application.add_controller(controller)
    application.configure()
    application.serve(endpoint)

    from concurrence import dispatch
    dispatch()
Exemple #4
0
def main(timeout=None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        Tasklet.later(timeout, quit,
                      name='unittest_timeout')(EXIT_CODE_TIMEOUT)

    dispatch(unittest.main)
Exemple #5
0
def main(timeout = None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        def quit_test():
            logging.error("quiting unittest on timeout")
            quit(EXIT_CODE_TIMEOUT)
        logging.debug("test will timeout in %s seconds", timeout)
        timeout_task = Tasklet.later(timeout, quit_test, name = 'unittest_timeout')()

    from concurrence.core import _profile
    #_profile(unittest.main)
    dispatch(unittest.main)
Exemple #6
0
def main(timeout = None, ontimeout = None):

    logging.basicConfig()
    logging.root.setLevel(logging.DEBUG)

    if timeout is not None:
        def quit_test():
            if ontimeout:
                ontimeout()
            logging.error("quiting unittest on timeout")
            quit(EXIT_CODE_TIMEOUT)
        logging.debug("test will timeout in %s seconds", timeout)
        timeout_task = Tasklet.later(timeout, quit_test, name = 'unittest_timeout')()

    from concurrence.core import _profile
    #_profile(unittest.main)
    dispatch(unittest.main)
Exemple #7
0
    
    reader_task = Tasklet.new(reader)()
    writer_task = Tasklet.new(writer)()

    MSG_WRITE_LINE.send(writer_task)("type 'quit' to exit..")
    
    for msg, args, kwargs in Tasklet.receive():
        if msg.match(MSG_QUIT):
            break
        elif msg.match(MSG_LINE_READ):
            #a line was recv from our client, multicast it to the other clients
            for task in connected_clients:
                if task != client_task: #don't echo the line back to myself
                    MSG_WRITE_LINE.send(task)(args[0])
        elif msg.match(MSG_WRITE_LINE):
            MSG_WRITE_LINE.send(writer_task)(args[0])
        
    connected_clients.remove(client_task)
    reader_task.kill()
    writer_task.kill()
    client_socket.close()
           
def server():
    """accepts connections on a socket, and dispatches
    new tasks for handling the incoming requests"""
    print 'listening for connections on port 9010'
    Server.serve(('localhost', 9010), handle)

if __name__ == '__main__':
    dispatch(server)
#! /usr/local/bin/stackless2.6
# by [email protected] at Thu Jan  7 15:28:10 CET 2010

import logging
import socket
import sys

import lprng

import concurrence
import concurrence.http.server
import concurrence.io.socket

def WsgiApplication(env, start_response):
  # Concurrence WSGIServer SUXX: no env['REMOTE_ADDR'] or env['REMOTE_HOST']
  print >>sys.stderr, 'info: got WSGI connection'
  start_response("200 OK", [('Content-Type', 'text/html')])
  if env['PATH_INFO'] in ('', '/'):
    return ['<a href="/0">start at 0</a><p>Hello, World!\n']
  else:
    num = int(env['PATH_INFO'][1:])
    next_num = lprng.Lprng(num).next()
    return ['<a href="/%d">continue with %d</a>\n' % (next_num, next_num)]

if __name__ == '__main__':
  logging.basicConfig()  # log errors to stderr.
  concurrence.io.socket.DEFAULT_BACKLOG = 128  # listen queue size
  server = concurrence.http.server.WSGIServer(WsgiApplication)
  server.serve(('127.0.0.1', 8080))
  concurrence.dispatch()
Exemple #9
0
                         "яблока")
        self.assertEqual(self.app.call("l10n.literal_value", 3, values),
                         "яблока")
        self.assertEqual(self.app.call("l10n.literal_value", 5, values),
                         "яблок")
        self.assertEqual(self.app.call("l10n.literal_value", 11, values),
                         "яблок")
        self.assertEqual(self.app.call("l10n.literal_value", 21, values),
                         "яблоко")
        values = "зелёное яблоко/зелёных яблока/зелёных яблок/зелёного яблока"
        self.assertEqual(self.app.call("l10n.literal_value", 0, values),
                         "зелёных яблок")
        self.assertEqual(self.app.call("l10n.literal_value", 1, values),
                         "зелёное яблоко")
        self.assertEqual(self.app.call("l10n.literal_value", 1.5, values),
                         "зелёного яблока")
        self.assertEqual(self.app.call("l10n.literal_value", 2, values),
                         "зелёных яблока")
        self.assertEqual(self.app.call("l10n.literal_value", 3, values),
                         "зелёных яблока")
        self.assertEqual(self.app.call("l10n.literal_value", 5, values),
                         "зелёных яблок")
        self.assertEqual(self.app.call("l10n.literal_value", 11, values),
                         "зелёных яблок")
        self.assertEqual(self.app.call("l10n.literal_value", 21, values),
                         "зелёное яблоко")


if __name__ == "__main__":
    dispatch(unittest.main)
Exemple #10
0
        self.assertEqual(self.dispatcher.request(req), "it worked")

    def testRetries(self):
        req = TestDispatcher.TestFailingRequest()
        self.assertEqual(self.dispatcher.request(req), "it worked")

    def testExceptions(self):
        req = TestDispatcher.TestFailingRequest()
        self.assertRaises(DeviceUnreachable, self.dispatcher.request, req, 0)
        self.assertEqual(self.dispatcher.request(req, 0), "it worked")

    def testVersion(self):
        dev = RadioDevice(self.dispatcher, 2)
        self.assertEqual(dev.protocol_version, 88)

    def testADC(self):
        dev = RadioDevice(self.dispatcher, 2)
        self.assertEqual(dev.adc_data(), [0, 1, 256, 1024, 65535, 184])

    def testSupplyVoltage(self):
        dev = RadioDevice(self.dispatcher, 2)
        self.assertEqual(dev.supply_voltage(), 7.64)

class TestRemoteDevice(EmulatedTest):
    def testVersion(self):
        dev = RadioDevice(self.dispatcher, 2)
        self.assertEqual(dev.protocol_version, 88)

if __name__ == "__main__":
    dispatch(unittest.main)
Exemple #11
0
def run():
    dispatch(main)
Exemple #12
0
def dispatch(initapp):
    concurrence.dispatch(lambda: main(initapp))
 def start(self):
     server = WSGIServer(wsgi_dispatcher)
     self.logger.info('%r dispatching...' % (self,))
     dispatch(server.serve(self.address))
Exemple #14
0
from concurrence import dispatch


def hello():
    print "Hello World!"


if __name__ == '__main__':
    dispatch(hello)
Exemple #15
0
        if not data: break
        print 'read', repr(data)

    start_response("200 OK", [])

    html = """
    <html>
    <body>
        <h1>blaat</h1>
    </body>
    </html>
    """
    return [html]

def main():
    application = WSGISimpleRouter()

    from wsgiref.validate import validator

    application.map('/form', validator(show_form))
    application.map('/upload', upload_form)
    application.map('/process', process_form)

    server = WSGIServer(application)
    server.serve(('localhost', 8080))

if __name__ == '__main__':
    import logging
    logging.basicConfig(level = logging.DEBUG)
    dispatch(main)
Exemple #16
0
def run():
    dispatch(main)
Exemple #17
0
def dispatch(initapp):
    concurrence.dispatch(lambda: main(initapp))
Exemple #18
0
        Tasklet.sleep(1.0)

def getter():
    while len(clients) < N:
        Tasklet.sleep(1.0)
    while True:
        #get
        with timer() as tmr:
            bts = 0
            for i in range(B):
                #print i
                stream = random.choice(clients)
                bts += get(stream, 'fooblaatpiet%d' % random.randint(0, KN))
        print 'getter', tmr.sec(B), '/sec', tmr.sec(bts / 1024.0 / 1024.0), 'Mb/sec'
        Tasklet.sleep(1.0)


def main():
    Tasklet.new(connector)()
    if sys.argv[1] == 'setter':
        Tasklet.new(setter)()
    elif sys.argv[1] == 'getter':
        Tasklet.new(getter)()
        Tasklet.new(truncator)()
    else:
        assert False, sys.argv

if __name__ == '__main__':
    logging.basicConfig()
    dispatch(main)
Exemple #19
0
from concurrence import dispatch

def hello():
    print "Hello World!"
    
if __name__ == '__main__':
    dispatch(hello)