diff options
Diffstat (limited to 'py/demo/Ice/async/Server.py')
-rwxr-xr-x | py/demo/Ice/async/Server.py | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/py/demo/Ice/async/Server.py b/py/demo/Ice/async/Server.py index 386dd77bb59..28ef53d796d 100755 --- a/py/demo/Ice/async/Server.py +++ b/py/demo/Ice/async/Server.py @@ -15,99 +15,99 @@ import Demo class CallbackEntry(object): def __init__(self, cb, delay): - self.cb = cb + self.cb = cb self.delay = delay class WorkQueue(threading.Thread): def __init__(self): threading.Thread.__init__(self) - self._callbacks = [] - self._done = False - self._cond = threading.Condition() + self._callbacks = [] + self._done = False + self._cond = threading.Condition() def run(self): self._cond.acquire() - try: - while not self._done: - if len(self._callbacks) == 0: - self._cond.wait() + try: + while not self._done: + if len(self._callbacks) == 0: + self._cond.wait() - if not len(self._callbacks) == 0: - self._cond.wait(self._callbacks[0].delay / 1000.0) + if not len(self._callbacks) == 0: + self._cond.wait(self._callbacks[0].delay / 1000.0) - if not self._done: - print "Belated Hello World!" - self._callbacks[0].cb.ice_response() - del self._callbacks[0] + if not self._done: + print "Belated Hello World!" + self._callbacks[0].cb.ice_response() + del self._callbacks[0] - for i in range(0, len(self._callbacks)): - self._callbacks[i].cb.ice_exception(Demo.RequestCanceledException()) - finally: - self._cond.release() + for i in range(0, len(self._callbacks)): + self._callbacks[i].cb.ice_exception(Demo.RequestCanceledException()) + finally: + self._cond.release() def add(self, cb, delay): self._cond.acquire() - try: - if not self._done: - entry = CallbackEntry(cb, delay) - if len(self._callbacks) == 0: - self._cond.notify() - self._callbacks.append(entry) - else: - cb.ice_exception(Demo.RequestCanceledException()) - finally: - self._cond.release() + try: + if not self._done: + entry = CallbackEntry(cb, delay) + if len(self._callbacks) == 0: + self._cond.notify() + self._callbacks.append(entry) + else: + cb.ice_exception(Demo.RequestCanceledException()) + finally: + self._cond.release() def destroy(self): self._cond.acquire() - try: - self._done = True - self._cond.notify() - finally: - self._cond.release() + try: + self._done = True + self._cond.notify() + finally: + self._cond.release() class HelloI(Demo.Hello): def __init__(self, workQueue): - self._workQueue = workQueue + self._workQueue = workQueue def sayHello_async(self, cb, delay, current=None): if delay == 0: - print "Hello World!" - cb.ice_response() - else: - self._workQueue.add(cb, delay) + print "Hello World!" + cb.ice_response() + else: + self._workQueue.add(cb, delay) def shutdown(self, current=None): self._workQueue.destroy() - self._workQueue.join() + self._workQueue.join() - current.adpater.getCommunicator().shutdown(); + current.adpater.getCommunicator().shutdown(); class Server(Ice.Application): def run(self, args): self.callbackOnInterrupt() - adapter = self.communicator().createObjectAdapter("Hello") - self._workQueue = WorkQueue() - adapter.add(HelloI(self._workQueue), self.communicator().stringToIdentity("hello")) - - self._workQueue.start() - adapter.activate() - - self.communicator().waitForShutdown() - return True + adapter = self.communicator().createObjectAdapter("Hello") + self._workQueue = WorkQueue() + adapter.add(HelloI(self._workQueue), self.communicator().stringToIdentity("hello")) + + self._workQueue.start() + adapter.activate() + + self.communicator().waitForShutdown() + return True def interruptCallback(self, sig): self._workQueue.destroy() - self._workQueue.join() + self._workQueue.join() - try: - self._communicator.destroy() - except: - traceback.print_exc() + try: + self._communicator.destroy() + except: + traceback.print_exc() app = Server() sys.exit(app.main(sys.argv, "config.server")) |