defrex / django-after-response Goto Github PK
View Code? Open in Web Editor NEWSimple asynchronous execution
License: MIT License
Simple asynchronous execution
License: MIT License
The function_queue variable is shared between all the threads on a process. If thread 1 adds something to the queue and then does some more processing and thread 2 comes along and finishes, even if it didn't add anything to the queue, it will process thread 1's function while thread 1 is still running.
You should replace function queue with a method that will pull the list from the threading.local and create it if it does not exist. Do not just put the variable in threading.local and leave it as a global variable. Then you'll just be sharing the thread local with all the other processes.
It should be something like this:
import threading
threadlocal = threading.local()
def function_queue():
queue = getattr(threadlocal, 'function_queue', None)
if v is None:
queue = []
setattr(threadlocal, 'function_queue', queue)
return queue
python --version
Python 3.4.2
from decorators import *
ImportError: No module named 'decorators'
Would be cool if the decorator could override the async option, so we can optimise for both safe and unsafe tasks.
I don't know how exactly this error occurs, but in my case i get the following error:
No handlers could be found for logger "after_response.signals"
More disturbing however is the fact that the database update I placed within the decorated function doesn't happen either.
I understand the function isn't getting executed but I have no idea why.
Any idea why this is happening?
I'm running django version 1.11.13 on Python 2.7.
$ pip install django-after-response==0.2.2
Collecting django-after-response==0.2.2
Could not find a version that satisfies the requirement django-after-response==0.2.2 (from versions: 0.1.0, 0.1.1, 0.2.0, 0.2.1)
No distributions matching the version for django-after-response==0.2.2
I had to install from git to get 0.2.2:
$ pip install git+git://github.com/defrex/django-after-response@98e00c766b5160b529a4ef810412eb9d2e6fc9a3
For me this is magic. I have no clue how I can execute code after the http response was sent to the client with django.
Could you please elaborate the README and explain how the magic works.
This would be very kind.
Regards,
Thomas Güttler
Hello,
Starting at version 0.2.0 I have many test fails because my tests expect synchronous execution of after-response callbacks.
I could add timers, but I think synchronous tests are more reliable.
Celery provides a CELERY_ALWAYS_EAGER option to disable asynchronous calls. Could you add something similar ?
Thank you,
Julien
I need to import a model into the after response, but I can not.
import after_response
@after_response.enable
def example():
from automacao.models import Automacao
Automacao.objects.count()
...
{ProgrammingError}relation "automacao" does not exist
LINE 1: SELECT COUNT(*) FROM "automacao" WHERE "automacao"."is_delet...
Hey there
Is there any way this could be adapted to create a progress bar?
for example, if one were to have a large function running, after_response would send a value out for jquery or ajax call to ingest at every iteration of a loop?
Cheers
I haven't been able to get any threading.Thread to work with uwsgi, including when using the django-after-response decorators. Has anyone experienced the same problem? I've actually written a more detailed explanation on stackoverflow: http://stackoverflow.com/questions/37930268/differences-between-uwsgi-and-gunicorn-when-running-async-calls
Thanks,
Because the setting is loaded to local variable, these test decodators do not work. I do not any problem to load the setting from the settings every time?
Now I have to import those and them override it manyally like: signals.AFTER_RESPONSE_RUN_ASYNC = False
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.