示例#1
0
        """Sends multiple hello messages by waiting given number of seconds
        inbetween."""

        times = [times]  # Workaround for Python 2.7's lacking of nonlocal

        def _cb(response):
            if times[0] > 0:
                response.append(
                    "Hello %s, sleeping for %d seconds for %d more time(s)." %
                    (name, seconds, times[0]))
                times[0] -= 1
                return deferLater(reactor, seconds, _cb, response)

            else:
                response.close()

        return Iterable.Push(_cb)


if __name__ == '__main__':
    application = initialize([SomeService, SomeNonBlockingService])
    resource = TwistedWebResource(application)
    site = Site(resource)

    reactor.listenTCP(port, site, interface=host)

    logging.info("listening on: %s:%d" % (host, port))
    logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port))

    sys.exit(reactor.run())
示例#2
0
文件: wsgi.py 项目: leobispo/spyne
    $ time curl -s "http://localhost:9757/block?seconds=10" > /dev/null & \
      time curl -s "http://localhost:9757/block?seconds=10" > /dev/null &
    [1] 27537
    [2] 27538

    real    0m10.031s
    user    0m0.008s
    sys     0m0.007s

    real    0m10.038s
    user    0m0.006s
    sys     0m0.006s
'''

host = '0.0.0.0'
port = 9757

if __name__=='__main__':
    application = initialize()
    wsgi_application = WsgiApplication(application)
    resource = WSGIResource(reactor, reactor, wsgi_application)
    site = Site(resource)

    reactor.listenTCP(port, site)

    logging.info('listening on: %s:%d' % (host,port))
    logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port))

    sys.exit(reactor.run())
示例#3
0
the reactor loop.

    $ time curl -s "http://localhost:9757/block?seconds=10" > /dev/null & \
      time curl -s "http://localhost:9757/block?seconds=10" > /dev/null &
    [1] 27559
    [2] 27560

    real    0m10.026s
    user    0m0.005s
    sys     0m0.008s

    real    0m20.045s
    user    0m0.009s
    sys     0m0.005s
'''

host = '0.0.0.0'
port = 9758

if __name__ == '__main__':
    application = initialize()
    resource = TwistedWebResource(application)
    site = Site(resource)

    reactor.listenTCP(port, site, interface=host)

    logging.info("listening on: %s:%d" % (host, port))
    logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port))

    sys.exit(reactor.run())
示例#4
0
from _service import initialize
from _service import SomeService

host = '0.0.0.0'
port = 9758


class SomeNonBlockingService(ServiceBase):
    @srpc(int)
    def sleep(seconds):
        """Waits without blocking reactor for given number of seconds by
        returning a deferred."""

        def _cb():
            return "slept for %r seconds" % seconds

        return deferLater(reactor, seconds, _cb)


if __name__=='__main__':
    application = initialize([SomeService, SomeNonBlockingService])
    resource = TwistedWebResource(application)
    site = Site(resource)

    reactor.listenTCP(port, site, interface=host)

    logging.info("listening on: %s:%d" % (host,port))
    logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port))

    sys.exit(reactor.run())
示例#5
0
    $ time curl -s "http://localhost:9757/block?seconds=10" > /dev/null & \
      time curl -s "http://localhost:9757/block?seconds=10" > /dev/null &
    [1] 27537
    [2] 27538

    real    0m10.031s
    user    0m0.008s
    sys     0m0.007s

    real    0m10.038s
    user    0m0.006s
    sys     0m0.006s
'''

host = '0.0.0.0'
port = 9757

if __name__ == '__main__':
    application = initialize([SomeService])
    wsgi_application = WsgiApplication(application)
    resource = WSGIResource(reactor, reactor, wsgi_application)
    site = Site(resource)

    reactor.listenTCP(port, site, interface=host)

    logging.info('listening on: %s:%d' % (host, port))
    logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port))

    sys.exit(reactor.run())
示例#6
0
文件: wsgi.py 项目: Bernie/spyne
    $ time curl -s "http://localhost:9757/block?seconds=10" > /dev/null & \
      time curl -s "http://localhost:9757/block?seconds=10" > /dev/null &
    [1] 27537
    [2] 27538

    real    0m10.031s
    user    0m0.008s
    sys     0m0.007s

    real    0m10.038s
    user    0m0.006s
    sys     0m0.006s
'''

host = '0.0.0.0'
port = 9757


if __name__=='__main__':
    application = initialize([SomeService])
    wsgi_application = WsgiApplication(application)
    resource = WSGIResource(reactor, reactor, wsgi_application)
    site = Site(resource)

    reactor.listenTCP(port, site, interface=host)

    logging.info('listening on: %s:%d' % (host,port))
    logging.info('wsdl is at: http://%s:%d/?wsdl' % (host, port))

    sys.exit(reactor.run())