{ "info": { "author": "Kevin Conway", "author_email": "kevinjacobconway@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "======\nengine\n======\n\n*Core event loop implementation.*\n\nThis package contains a configurable event loop and a set of hooks that allow\nfor async networking, time based scheduling, and coroutine management. Below\nare samples of using each of the major components. Use caution. This project\nis still very much in its infancy.\n\nExample Usage\n=============\n\nAsync Networking\n----------------\n\n.. code-block:: python\n\n # Create a non-blocking socket server that logs data and closes connections.\n\n import functools\n import socket\n\n from asyncdef.engine.core import Engine\n from asyncdef.engine.processors.selector import Selector\n\n # Generate a non-blocking socket listener.\n sock = socket.socket()\n sock.setblocking(0)\n sock.bind(('localhost', 9898))\n sock.listen()\n\n\n def handle_data(selector, conn):\n \"\"\"Triggered on data waiting for read.\"\"\"\n data = conn.recv(4096)\n print('Got data {}.'.format(data))\n selector.remove_reader(conn)\n conn.close()\n\n\n def handle_connection(selector, listening_socket):\n \"\"\"Triggered on new incoming connection.\"\"\"\n conn, addr = listening_socket.accept()\n conn.setblocking(0)\n selector.add_reader(\n conn,\n functools.partial(handle_data, selector),\n )\n\n # Create an instance of the selector and event loop.\n selector = Selector()\n loop = Engine(selector)\n\n # Set up the socket polling.\n selector.add_reader(sock, functools.partial(handle_connection, selector))\n\n # Start the event loop.\n loop.start()\n\nTime Scheduling\n---------------\n\n.. code-block:: python\n\n # Schedule a function to run in five seconds.\n import functools\n\n from asyncdef.engine.core import Engine\n from asyncdef.engine.processors.time import Time\n\n\n def print_and_stop(loop):\n print(\"Stopping the loop.\")\n loop.stop()\n\n time = Time()\n loop = Engine(time)\n handle = loop.defer_for(5, functools.partial(print_and_stop, loop))\n\n loop.start()\n\nCoroutine Management\n--------------------\n\n.. code-block:: python\n\n import functools\n from concurrent.futures import Future\n\n from asyncdef.engine.core import Engine\n from asyncdef.engine.processors.coroutine import Coroutine\n from asyncdef.engine.processors.time import Time\n\n\n class AwaitableFuture(Future):\n\n \"\"\"An awaitable version of the standard lib Future.\"\"\"\n\n def __await__(self):\n \"\"\"Return self until resolved.\"\"\"\n while self._state != 'FINISHED':\n\n yield self\n\n return self.result()\n\n\n async def wait_for_future(loop, future):\n value = await future\n print('Got value {}. Stopping the loop.'.format(value))\n loop.stop()\n\n\n def resolve_future(future):\n print('Resolving future.')\n future.set_result(True)\n\n time = Time()\n coromgr = Coroutine()\n loop = Engine(coromgr, time)\n\n future = AwaitableFuture()\n time.defer_for(5, functools.partial(resolve_future, future))\n handle = coromgr.add(wait_for_future(loop, future))\n\n loop.start()\n\nTesting\n=======\n\nAll tests suites are paired one-to-one with the module they test and live\ndirectly adjacent to that same module. All tests are expected to pass for\nPython 3.5 and above. To run tests use tox with the included tox.ini file or\ncreate a virtualenv and install the '[testing]' extras.\n\nLicense\n=======\n\n Copyright 2016 Kevin Conway\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\nContributing\n============\n\nFirstly, if you're putting in a patch then thank you! Here are some tips for\ngetting your patch merged:\n\nStyle\n-----\n\nAs long as the code passes the PEP8 and PyFlakes gates then the style is\nacceptable.\n\nDocs\n----\n\nThe PEP257 gate will check that all public methods have docstrings. If you're\nadding something new, like a helper function, try out the\n`napoleon style of docstrings `_.\n\nTests\n-----\n\nMake sure the patch passes all the tests. If you're adding a new feature don't\nforget to throw in a test or two. If you're fixing a bug then definitely add\nat least one test to prevent regressions.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/asyncdef/engine", "keywords": null, "license": "Apache 2.0", "maintainer": null, "maintainer_email": null, "name": "asyncdef.engine", "package_url": "https://pypi.org/project/asyncdef.engine/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/asyncdef.engine/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/asyncdef/engine" }, "release_url": "https://pypi.org/project/asyncdef.engine/0.1.1/", "requires_dist": null, "requires_python": null, "summary": "Core event loop implementation.", "version": "0.1.1" }, "last_serial": 2083995, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "9c850885bf5bad84b483ed459b823f65", "sha256": "e781cb8280cb73ff8087da30e110b0f111359ddeaae85474bb7d2089df036dea" }, "downloads": -1, "filename": "asyncdef.engine-0.1.0.tar.gz", "has_sig": false, "md5_digest": "9c850885bf5bad84b483ed459b823f65", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15183, "upload_time": "2016-03-27T14:48:59", "url": "https://files.pythonhosted.org/packages/b6/f9/ee8b07674fdba7f3cb9194ccb9ab1dd4bd5e30a8593df56d0e9b3a72429f/asyncdef.engine-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "075bc25e5f61e94473d4baafa2b01413", "sha256": "a7e02139087f1ac6a65e3f11fb7417c245d801a21197bc08e813e49b5cdaae34" }, "downloads": -1, "filename": "asyncdef.engine-0.1.1.tar.gz", "has_sig": false, "md5_digest": "075bc25e5f61e94473d4baafa2b01413", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15188, "upload_time": "2016-04-26T03:56:12", "url": "https://files.pythonhosted.org/packages/4e/ab/ce99c24f74074173dcfbc3e7557a64a0ffcaf0d071b48011cf5108649126/asyncdef.engine-0.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "075bc25e5f61e94473d4baafa2b01413", "sha256": "a7e02139087f1ac6a65e3f11fb7417c245d801a21197bc08e813e49b5cdaae34" }, "downloads": -1, "filename": "asyncdef.engine-0.1.1.tar.gz", "has_sig": false, "md5_digest": "075bc25e5f61e94473d4baafa2b01413", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15188, "upload_time": "2016-04-26T03:56:12", "url": "https://files.pythonhosted.org/packages/4e/ab/ce99c24f74074173dcfbc3e7557a64a0ffcaf0d071b48011cf5108649126/asyncdef.engine-0.1.1.tar.gz" } ] }