I have set up an admin command in django:
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
""" Command to parse logs that can be called from django """
def handle(self, *args, **options):
parse_logs()
I can call either from shell or python with call_command. When I call it from the view this command stops all other requests to the app from working until it is finished.
I would like to be able to run this command in the background, maybe using a separate Thread, and displaying the results of the command on the webpage without having to reload the page. For example:
You could use the subprocess module (Popen) to execute the management command as a separate process (thus liberating your view from having to wait until the command is done).
The process could set some kind of flag when it's done. Then you would poll the server for results until they are available, i.e. the flag has been set
The process would also have to be able to communicate results once they're available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With