1đź‘Ť
I would suggest you to configure cron to run your command at specific times/intervals.
- [Answer]-Django query with annotated conditional expression uses INNER JOIN. How do I get it to use OUTER JOIN?
- [Answer]-Django, adding a readonly field (from instance method) to a modelform.
- [Answer]-"ImportError: No module named 'tastypie'" when running "django-admin migrate"
- [Answer]-Views VS App in Django?
- [Answer]-Django: Page not found (404) and not getting data from models in templates
0đź‘Ť
I would say handle this through cross, but if you don’t want to use cross then:
Make sure you installed the module in the virtualenv (With easy_install, pip, or any other way that Amazon EC2 allows). After that you might want to look up the threading module documentation:
Python 2 threading module documentation
Python 3 threading module documentation
The purpose of using threading will be to have the following structure:
A “control” thread, which will use the chronograph module and do the time measurements, and putting the new work to do in an “input queue” on each scheduled time, for the worker threads (which will be active already) to process, or just trigger each worker thread (make it active) at the time you want to trigger each execution.
In the first case you’ll be taking advantage of parallel threads to do a big chunk of work and minimize io wait times, but since the work is in a queue, the workers will process one at a time. Meaning if you schedule two things too close together and the previous element is still being processed, the new item will have to wait (Depending on your programming logic and amount of worker threads some workers might start processing the new item, but is a bit more complex logic).
In the second case your control thread will actually trigger the start of a new thread (or group of threads) each time you want to trigger a scheduled action. If there’s big data to process you might need to spawn a new queue for each task to process and create a group of worker threads for it for each task, but if the data is not that big then you can just get away with having the worker process just one data package and be done once execution is done and you get a result. Either way this method will allow you to schedule tasks without limitation on how close they can be, since new independent worker threads will be created for them every time.
Finally, you might want to create an “output queue” and output thread, to store and process (or output, or anything else you want to do with it…) the results of each worker threads.
The control thread will be basically trying to imitate cron in its logic, triggering actions at certain times depending on how it was configured.
There’s also a multiprocessing module in python which will work with processes instead and take advantage of true multiprocessing hardware, but I don’t think you’ll really need it in this case, unless you see performance issues caused by cpu performance.
If you need any clarification, help, examples, just let me know.
- [Answer]-Django template rendering extend tag incorrectly
- [Answer]-Django cannot read session under subdomain but working under IP Address
- [Answer]-Django NOT NULL constraint failed: pages_newlist.user_id
- [Answer]-Django + Extjs 5.1.1
- [Answer]-Django manage.py syncdb : expected string or buffer?