简体   繁体   中英

How can I run a Django management command asynchronously?

I have a Django management command that I'd like to issue in an asynchronous manner (via the call_command function). The flow of my code looks something like:

  1. User fills out a web form (or edits pre-existing values in a form).
  2. User clicks the submit button, and I do some processing.
  3. Once processing is done, I'd like to issue a management command without forcing the user to wait for it to return .

If the management command fails for some reason, I'm not too concerned (my logs will catch those cases), so allowing the user to proceed on their merry way is fine by me.

Is this kind of asynchronous call possible, and if so, how best can I do it? Is the threading library sufficient for this case? I'm aware of packages like Celery , but using something like that seems like tremendous overkill for something as simple as what I'm trying to do.

Thats an easy one!

Just use django-rq . Easy as a pie.

I, personally, use it for sending emails asychronously which otherwise user had to wait about 11s. Just made my life easier. Its lightweight and I love it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM