async def run(self): while True: try: client = await self.conn.accept() kore.task_create(self.handle_client(client)) client = None except Exception as e: kore.fatal("exception %s" % e)
def start(self): """ Start actor. """ assert self._mailbox is None and self._waiting is None self._mailbox = kore.queue() self._waiting = [] kore.task_create(self._dispatch(self._mailbox))
client = None except Exception as e: kore.fatal("exception %s" % e) # Each client will run as this co-routine. # In this case we pass a timeout of 1 second to the recv() call # which will throw a TimeoutError exception in case the timeout # is hit before data is read from the socket. # # This timeout argument is optional. If none is specified the call # will wait until data becomes available. async def handle_client(self, client): while True: try: data = await client.recv(1024, 1000) if data is None: break await client.send(data) except TimeoutError as e: print("timed out reading (%s)" % e) except Exception as e: print("client got exception %s" % e) client.close() # Setup the server object. server = EchoServer() # Create a task that will execute inside of Kore as a co-routine. kore.task_create(server.run())
kore.task_create(self.handle_client(client)) client = None except Exception as e: kore.fatal("exception %s" % e) # Each client will run as this co-routine. # In this case we pass a timeout of 1 second to the recv() call # which will throw a TimeoutError exception in case the timeout # is hit before data is read from the socket. # # This timeout argument is optional. If none is specified the call # will wait until data becomes available. async def handle_client(self, client): while True: try: data = await client.recv(1024, 1000) if data is None: break await client.send(data) except TimeoutError as e: print("timed out reading (%s)" % e) except Exception as e: print("client got exception %s" % e) client.close() # Setup the server object. server = EchoServer() # Create a task that will execute inside of Kore as a co-routine. kore.task_create(server.run())
def kore_worker_configure(): kore.task_create(queue_helper())
# # Copyright (c) 2018 Joris Vink <*****@*****.**> # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # import kore import async_http import async_queue import async_socket import async_process import async_process kore.server(ip="127.0.0.1", port="8888", tls=False) kore.domain("*") kore.task_create(async_queue.queue_helper())