Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gdoermann/twango
twango = Django ORM + Twisted - Blocking
https://github.com/gdoermann/twango
Last synced: about 2 months ago
JSON representation
twango = Django ORM + Twisted - Blocking
- Host: GitHub
- URL: https://github.com/gdoermann/twango
- Owner: gdoermann
- License: mit
- Created: 2011-07-26T22:11:56.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2017-10-04T21:09:09.000Z (over 7 years ago)
- Last Synced: 2024-10-29T02:49:04.025Z (2 months ago)
- Language: Python
- Homepage:
- Size: 47.9 KB
- Stars: 19
- Watchers: 6
- Forks: 7
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: MIT-LICENSE.txt
Awesome Lists containing this project
README
twango = Django ORM + Twisted - Blocking
----------------------------------------
This is a library that contains a custom queryset and a custom manager that adds introspection to use
the twisted database api instead of django. It returns deferred instead of just hitting the database.To install:
-----------
1. Run python setup.py
2. Import and set the manager as the manager for any modelThis will keep the orm from blocking when using the django orm!
Important
-----------
Does not make job in asynchronous way, but goes into threads and do not perform blocking main reactor.Example Updated:
--------Returns defered.
Does any methods call except "all", eg: Book.twisted.all()
```python
d = Book.twisted.count()
d.addCallback(do_something)
```Aslo "success_callback" and "error_callback" can be passed
```python
d = Book.twisted.count(success_callback=do_something)
d.addCallback(do_something2)
```Calling "all" method similarly, returns defered but does not accept any arguments
```python
d = Book.twisted.all()
d.addCallback(do_something)
```Example:
--------
You can create models that are separate to be used in twisted processes:```python
from myapp import Book
from twango.manager import TwistedManager
from django.db.models.manager import Managerclass TwistedBook(Book):
objects = Manager()
twisted = TwistedManager()class Meta:
app_label = 'myapp'
proxy = True
```Then you can use the twisted manager like you would with the regular manager... just with callbacks!
```python
def count_me(count):
print "Count: %s" % countdef all(queryset):
print 'All: %s' % querysetdef none(queryset):
print 'None: %s' % querysetdef callback(*args, **kwargs):
Book.twisted.count(success_callback=count_me)
Book.twisted.all(success_callback=all)
Book.twisted.none(success_callback=none)d = Deferred()
d.addCallback(callback)
d.callback(None)reactor.run()
```