Beispiel #1
0
def main():
    basicConfig(level=DEBUG)
    thing = Thing()
    context = Context('0', Progress(), Cancelled())
    Context.set(context)
    call = Call(thing.echo, 10000)
    print(call())
Beispiel #2
0
 def __call__(self):
     """
     Dispatch received request.
     """
     request = self.request
     cancelled = Cancelled(request.sn)
     latency = self.plugin.latency
     if latency:
         sleep(latency)
     if not self.plugin.url or cancelled():
         self.discard()
         return
     producer = self._producer(self.plugin)
     progress = Progress(request, producer)
     context = Context(request.sn, progress, cancelled)
     Context.set(context)
     producer.open()
     try:
         self.producer = producer
         self.send_started(request)
         result = self.plugin.dispatch(request)
         self.send_reply(request, result)
         self.commit()
     finally:
         producer.close()
         Context.set()
Beispiel #3
0
 def __call__(self):
     """
     Dispatch received request.
     """
     request = self.request
     cancelled = Cancelled(request.sn)
     latency = self.plugin.latency
     if latency:
         sleep(latency)
     if not self.plugin.url or cancelled():
         self.discard()
         return
     producer = self._producer(self.plugin)
     progress = Progress(request, producer)
     context = Context(request.sn, progress, cancelled)
     Context.set(context)
     producer.open()
     try:
         self.producer = producer
         self.send_started(request)
         result = self.plugin.dispatch(request)
         self.send_reply(request, result)
         self.commit()
     finally:
         producer.close()
         Context.set()
Beispiel #4
0
 def test_set(self):
     context = Context('1', Mock(), Mock())
     Context.set(context)
     # set
     self.assertEqual(Context._current.inst, context)
     # clear
     Context.set()
     self.assertEqual(Context._current.inst, None)
Beispiel #5
0
 def test_set(self):
     context = Context("1", Mock(), Mock())
     Context.set(context)
     # set
     self.assertEqual(Context._current.inst, context)
     # clear
     Context.set()
     self.assertEqual(Context._current.inst, None)