{"id":13494995,"url":"https://github.com/dabeaz/curio","last_synced_at":"2025-05-13T19:17:38.074Z","repository":{"id":37587751,"uuid":"44054354","full_name":"dabeaz/curio","owner":"dabeaz","description":"Good Curio!","archived":false,"fork":false,"pushed_at":"2024-10-04T18:34:19.000Z","size":2370,"stargazers_count":4092,"open_issues_count":22,"forks_count":247,"subscribers_count":143,"default_branch":"master","last_synced_at":"2025-04-27T20:02:56.968Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dabeaz.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-11T14:02:00.000Z","updated_at":"2025-04-27T11:38:26.000Z","dependencies_parsed_at":"2022-07-12T16:32:23.415Z","dependency_job_id":"99a4c225-9339-48fe-8dca-84da6c85a187","html_url":"https://github.com/dabeaz/curio","commit_stats":{"total_commits":816,"total_committers":59,"mean_commits":"13.830508474576272","dds":"0.23039215686274506","last_synced_commit":"5d8ecb2333761b4fd629e14d940f3807d143c0ed"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabeaz%2Fcurio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabeaz%2Fcurio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabeaz%2Fcurio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dabeaz%2Fcurio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dabeaz","download_url":"https://codeload.github.com/dabeaz/curio/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010830,"owners_count":21999004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:30.189Z","updated_at":"2025-05-13T19:17:38.053Z","avatar_url":"https://github.com/dabeaz.png","language":"Python","funding_links":[],"categories":["Python","备选事件循环","Alternatives to asyncio"],"sub_categories":[],"readme":"Curio\n=====\n\nCurio is a coroutine-based library for concurrent Python systems\nprogramming using async/await.  It provides standard programming\nabstractions such as tasks, sockets, files, locks, and queues as\nwell as some advanced features such as support for structured\nconcurrency. It works on Unix and Windows and has zero dependencies.\nYou'll find it to be familiar, small, fast, and fun.\n\nImportant Notice: October 25, 2022\n----------------------------------\nThe Curio project is no longer making package releases.  I'm more than\nhappy to accept bug reports and may continue to work on it from time\nto time as the mood strikes.  If you want the absolute latest version, you\nshould vendor the source code from here. Curio has no dependencies\nother than the Python standard library.  --Dave\n\nCurio is Different\n------------------\nOne of the most important ideas from software architecture is the\n\"separation of concerns.\"  This can take many forms such as utilizing\nabstraction layers, object oriented programming, aspects, higher-order\nfunctions, and so forth.  However, another effective form of it exists\nin the idea of separating execution environments.  For example, \"user\nmode\" versus \"kernel mode\" in operating systems.  This is the\nunderlying idea in Curio, but applied to \"asynchronous\" versus\n\"synchronous\" execution.\n\nA fundamental problem with asynchronous code is that it involves a\ncompletely different evaluation model that doesn't compose well with\nordinary applications or with other approaches to concurrency such as\nthread programing.  Although the addition of \"async/await\" to Python\nhelps clarify such code, \"async\" libraries still tend to be a confused\nmess of functionality that mix asynchronous and synchronous\nfunctionality together in the same environment--often bolting it all\ntogether with an assortment of hacks that try to sort out all of\nassociated API confusion.\n\nCurio strictly separates asynchronous code from synchronous code.\nSpecifically, *all* functionality related to the asynchronous\nenvironment utilizes \"async/await\" features and syntax--without\nexception.  Moreover, interactions between async and sync code is\ncarefully managed through a small set of simple mechanisms such as\nevents and queues.  As a result, Curio is small, fast, and\nsignificantly easier to reason about.\n\nA Simple Example\n-----------------\n\nHere is a concurrent TCP echo server directly implemented using sockets:\n\n.. code:: python\n\n    # echoserv.py\n    \n    from curio import run, spawn\n    from curio.socket import *\n    \n    async def echo_server(address):\n        sock = socket(AF_INET, SOCK_STREAM)\n        sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)\n        sock.bind(address)\n        sock.listen(5)\n        print('Server listening at', address)\n        async with sock:\n            while True:\n                client, addr = await sock.accept()\n                await spawn(echo_client, client, addr, daemon=True)\n    \n    async def echo_client(client, addr):\n        print('Connection from', addr)\n        async with client:\n             while True:\n                 data = await client.recv(100000)\n                 if not data:\n                     break\n                 await client.sendall(data)\n        print('Connection closed')\n\n    if __name__ == '__main__':\n        run(echo_server, ('',25000))\n\nIf you've done network programming with threads, it looks almost\nidentical. Moreover, it can handle thousands of clients even though no\nthreads are being used inside.\n\nCore Features\n-------------\n\nCurio supports standard synchronization primitives (events, locks,\nrecursive locks, semaphores, and condition variables), queues,\nsubprocesses, as well as running tasks in threads and processes.  The\ntask model fully supports cancellation, task groups, timeouts,\nmonitoring, and other features critical to writing reliable code.\n\nRead the `official documentation \u003chttps://curio.readthedocs.io\u003e`_ for\nmore in-depth coverage.  The `tutorial\n\u003chttps://curio.readthedocs.io/en/latest/tutorial.html\u003e`_ is a good\nstarting point.  The `howto\n\u003chttps://curio.readthedocs.io/en/latest/howto.html\u003e`_ describes how to\ncarry out common programming tasks.\n\nTalks Related to Curio\n----------------------\n\nConcepts related to Curio's design and general issues related to async\nprogramming have been described by Curio's creator, `David Beazley \u003chttps://www.dabeaz.com\u003e`_, in\nvarious conference talks and tutorials:\n\n* `Build Your Own Async \u003chttps://www.youtube.com/watch?v=Y4Gt3Xjd7G8\u003e`_, Workshop talk by David Beazley at PyCon India, 2019.\n\n* `The Other Async (Threads + Asyncio = Love) \u003chttps://www.youtube.com/watch?v=x1ndXuw7S0s\u003e`_, Keynote talk by David Beazley at PyGotham, 2017.\n\n* `Fear and Awaiting in Async \u003chttps://www.youtube.com/watch?v=E-1Y4kSsAFc\u003e`_, Keynote talk by David Beazley at PyOhio 2016.\n\n* `Topics of Interest (Async) \u003chttps://www.youtube.com/watch?v=ZzfHjytDceU\u003e`_, Keynote talk by David Beazley at Python Brasil 2015.\n\n* `Python Concurrency from the Ground Up (LIVE) \u003chttps://www.youtube.com/watch?v=MCs5OvhV9S4\u003e`_, talk by David Beazley at PyCon 2015.\n\nQuestions and Answers\n---------------------\n\n**Q: What is the point of the Curio project?**\n\nA: Curio is async programming, reimagined as something smaller, faster, and easier \nto reason about. It is meant to be both educational and practical.\n\n**Q: Is Curio implemented using asyncio?**\n\nA: No. Curio is a standalone library directly created from low-level I/O primitives.\n\n**Q: Is Curio meant to be a clone of asyncio?**\n\nA: No. Although Curio provides a significant amount of overlapping\nfunctionality, the API is different.  Compatibility with other\nlibaries is not a goal.\n\n**Q: Is Curio meant to be compatible with other async libraries?**\n\nA: No. Curio is a stand-alone project that emphasizes a certain\nsoftware architecture based on separation of environments.  Other\nlibraries have largely ignored this concept, preferring to simply\nprovide variations on the existing approach found in asyncio.\n\n**Q: Can Curio interoperate with other event loops?**\n\nA: It depends on what you mean by the word \"interoperate.\"  Curio's\npreferred mechanism of communication with the external world is a\nqueue.  It is possible to communicate between Curio, threads, and\nother event loops using queues.  \n\n**Q: How fast is Curio?**\n\nA: Curio's primary goal is to be an async library that is minimal and\nunderstandable. Performance is not the primary concern.  That said, in\nrough benchmarking of a simple echo server, Curio is more than twice\nas fast as comparable code using coroutines in ``asyncio`` or\n``trio``.  This was last measured on OS-X using Python 3.9.  Keep in\nmind there is a lot more to overall application performance than the\nperformance of a simple echo server so your mileage might\nvary. However, as a runtime environment, Curio doesn't introduce a lot of\nextra overhead. See the ``examples/benchmark`` directory for various\ntesting programs.\n\n**Q: What is the future of Curio?**\n\nA: Curio should be viewed as a library of basic programming\nprimitives.  At this time, it is considered to be\nfeature-complete--meaning that it is not expected to sprout many new\ncapabilities.  It may be updated from time to time to fix bugs or\nsupport new versions of Python.\n\n**Q: Can I contribute?**\n\nA: Curio is not a community-based project seeking developers\nor maintainers.  However, having it work reliably is important. If you've\nfound a bug or have an idea for making it better, please \nfile an `issue \u003chttps://github.com/dabeaz/curio\u003e`_. \n\nContributors\n------------\n\nThe following people contributed ideas to early stages of the Curio project:\nBrett Cannon, Nathaniel Smith, Alexander Zhukov, Laura Dickinson, and Sandeep Gupta.\n\nWho\n---\nCurio is the creation of David Beazley (@dabeaz) who is also\nresponsible for its maintenance.  http://www.dabeaz.com\n\nP.S.\n----\nIf you want to learn more about concurrent programming more generally, you should\ncome take a `course \u003chttps://www.dabeaz.com/courses.html\u003e`_!\n\n.. |--| unicode:: U+2013   .. en dash\n.. |---| unicode:: U+2014  .. em dash, trimming surrounding whitespace\n   :trim:\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabeaz%2Fcurio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdabeaz%2Fcurio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdabeaz%2Fcurio/lists"}