Skip to content

Commit

Permalink
local proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
divi255 committed Jul 20, 2019
1 parent 329a5a1 commit dc2fb0c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
tasks
workers
collections
localproxy
27 changes: 27 additions & 0 deletions doc/localproxy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Thread local proxy
******************

Simple proxy for *threading.local* namespace.

.. code:: python
from atasker import g
if not g.has('db'):
g.set('db', <new_db_connection>)
Supports methods:

.. code:: python
# returns attr value or default value if specified
g.get(attr, default=None)
# returns True if attribute exists
g.has(attr)
# set attribute value
g.set(attr, value)
# delete attribute
g.clear(attr)
8 changes: 7 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ def wait():

from atasker import task_supervisor, background_task, background_worker, TT_MP

from atasker import FunctionCollection, TaskCollection
from atasker import FunctionCollection, TaskCollection, g


class Test(unittest.TestCase):

def test_g(self):
g.set('test', 1)
g.clear('test')
g.set('test_is', g.has('test'))
self.assertFalse(g.get('test_is'))

def test_function_collection(self):

f = FunctionCollection()
Expand Down

0 comments on commit dc2fb0c

Please sign in to comment.