{ "info": { "author": "Alberto Berti", "author_email": "alberto@metapensiero.it", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5" ], "description": ".. -*- coding: utf-8 -*-\n.. :Project: metapensiero.asyncio.tasklocal -- An asyncio's Task-local variable container\n.. :Created: dom 09 ago 2015 12:57:35 CEST\n.. :Author: Alberto Berti \n.. :License: GNU General Public License version 3 or later\n.. :Copyright: Copyright (C) 2015 Alberto Berti\n..\n\n================================\n metapensiero.asyncio.tasklocal\n================================\n\n :author: Alberto Berti\n :contact: alberto@metapensiero.it\n :license: GNU General Public License version 3 or later\n\nAn asyncio's Task-local variable container\n==========================================\n\nUsage\n+++++\n\nA drop-in replacement for ``threading.local`` object that stores\nper-task variables (instead of per-thread). You can use it like this::\n\n import asyncio\n from metapensiero.asyncio.tasklocal import Local\n\n mylocal = Local()\n\n @asyncio.coroutine\n def task_a():\n mylocal.a_var = 'foo'\n yield from asyncio.sleep(0.001) # switches to task_b\n assert mylocal.a_var == 'foo'\n print(mylocal.a_var)\n\n @asyncio.coroutine\n def task_b():\n mylocal.a_var = 'bar'\n yield from asyncio.sleep(0.001) # switches back to task_a\n assert mylocal.a_var == 'bar'\n print(mylocal.a_var)\n\n loop = asyncio.get_event_loop()\n a = asyncio.Task(task_a())\n b = asyncio.Task(task_b())\n loop.run_until_complete(asyncio.wait((a, b)))\n\n # this prints out:\n # foo\n # bar\n\nReally the kind of object to be tracked as \"current\" is configurable\nby passing-in a different ``Discriminator`` instance to the ``Local``\nclass.\n\nBy default it will use the ``TaskDiscriminator`` supplied with the\npackage. It will use standard ``asyncio``'s loop detection techniques\n(by delegating it to ``asyncio.Task.current_task()``) but if you want\nto track tasks of a particular event loop, you can supply your own\n``TaskDiscriminator`` instance to the ``Local`` instance\ninitialization, like this::\n\n from metapensiero.asyncio.tasklocal import Local, TaskDiscriminator\n\n mylocal = Local(discriminator=TaskDiscriminator(loop=my_loop))\n\nYou can also track another set of object by subclassing the\n``BaseDiscriminator`` class::\n\n from metapensiero.asyncio.tasklocal import BaseDiscriminator\n\n class ASampleSessionDiscriminator(BaseDiscriminator):\n\n def current(self):\n return current_session()\n\n mylocal = Local(discriminator=ASampleDiscriminator())\n\nYou have to implement at least the ``current`` method.\n\nLike ``threading.local`` class, this class supports subclassing, in\nwhich case it will re-execute the ``__init__`` method for each one of\nthe tracked objects::\n\n call_counter = 0\n\n class CustomLocal(Local):\n\n a_value = None\n\n def __init__(self, a_value):\n self.a_value = a_value\n nonlocal call_counter\n call_counter += 1\n\n mylocal = CustomLocal('foo')\n\nHere ``mylocal.a_value`` will be initialized to ``foo`` for every\ntracked object (asyncio's tasks by default). Here ``call_counter``\nwill count the number of every tracked object in which the ``mylocal``\nobject has been accessed.\n\nTesting\n+++++++\n\nTo run the tests you should run the following at the package root::\n\n python setup.py test\n\nBuild status\n++++++++++++\n\n.. image:: https://travis-ci.org/azazel75/metapensiero.asyncio.tasklocal.svg?branch=master\n :target: https://travis-ci.org/azazel75/metapensiero.asyncio.tasklocal\n\n\n.. -*- coding: utf-8 -*-\n\nChanges\n-------\n\n\n0.1 (2015-12-14)\n~~~~~~~~~~~~~~~~\n\n- First release complete with tests\n\n0.2 (2015-12-26)\n~~~~~~~~~~~~~~~~\n\n- Fix CHANGES and packaging", "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/azazel75/metapensiero.asyncio.tasklocal", "keywords": "", "license": "GPLv3+", "maintainer": null, "maintainer_email": null, "name": "metapensiero.asyncio.tasklocal", "package_url": "https://pypi.org/project/metapensiero.asyncio.tasklocal/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/metapensiero.asyncio.tasklocal/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/azazel75/metapensiero.asyncio.tasklocal" }, "release_url": "https://pypi.org/project/metapensiero.asyncio.tasklocal/0.2/", "requires_dist": null, "requires_python": null, "summary": "An asyncio's Task-local variable container", "version": "0.2" }, "last_serial": 1878127, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "2b8191bbadc5d2483c85b81114be731d", "sha256": "fd60067eeea9cc1aa100c12035a1da03af9b5a7e54d8ab3a0d1241938ad82d2e" }, "downloads": -1, "filename": "metapensiero.asyncio.tasklocal-0.1.tar.gz", "has_sig": false, "md5_digest": "2b8191bbadc5d2483c85b81114be731d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4531, "upload_time": "2015-12-14T13:48:34", "url": "https://files.pythonhosted.org/packages/bc/b4/a20a0016740a46a045242d172ebb23b2f5bb40ede3158b8620e8c9caa4de/metapensiero.asyncio.tasklocal-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "b1f843b8feae8f338b42878b5bfe4ac3", "sha256": "a77ca539ea68636d5b682032c327d038d315b6dd0228646ca4f8998662643c0d" }, "downloads": -1, "filename": "metapensiero.asyncio.tasklocal-0.2.tar.gz", "has_sig": false, "md5_digest": "b1f843b8feae8f338b42878b5bfe4ac3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4670, "upload_time": "2015-12-26T15:52:29", "url": "https://files.pythonhosted.org/packages/9d/f5/18985d83c21bd58d0d6ab680938a1125fb395bd389f08fdd80f8c167bcce/metapensiero.asyncio.tasklocal-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "b1f843b8feae8f338b42878b5bfe4ac3", "sha256": "a77ca539ea68636d5b682032c327d038d315b6dd0228646ca4f8998662643c0d" }, "downloads": -1, "filename": "metapensiero.asyncio.tasklocal-0.2.tar.gz", "has_sig": false, "md5_digest": "b1f843b8feae8f338b42878b5bfe4ac3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4670, "upload_time": "2015-12-26T15:52:29", "url": "https://files.pythonhosted.org/packages/9d/f5/18985d83c21bd58d0d6ab680938a1125fb395bd389f08fdd80f8c167bcce/metapensiero.asyncio.tasklocal-0.2.tar.gz" } ] }