Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I currently have a project with similar requirements (just more complicated^^).</p> <p>Never spawn a subprocess or thread from your Django view. You have no control of the Django processes and it could be killed, paused etc before the end of the task. It is controlled by the web server (e.g. apache via WSGI).</p> <p>What I would do is an external script, which would run in a separate process. You have two solutions I think :</p> <ul> <li>A process that is always running and crawling the directory where you put your files. It would for example check the directory every ten seconds and process the files</li> <li>Same as above, but run by cron every x seconds. This basically has the same effect</li> <li>Use Celery to create worker processes and add jobs to the queue with your Django application. Then you will need to get the results back by one of the means available with Celery.</li> </ul> <p>Now you probably need to access the information in Django models to email the user in the end. Here you have several solutions :</p> <ul> <li>Import your modules (models etc) from the external script</li> <li>Implement the external script as a custom command (as knutin suggested)</li> <li>Communicate the results to the Django application via a POST request for example. Then you would do the email sending and status changes etc in a normal Django view.</li> </ul> <p>I would go for an external process and import the modules or POST request. This way it is much more flexible. You could for example make use of the multiprocessing module to process several files in the same time (thus using multi-core machines efficiently).</p> <p>A basic workflow would be:</p> <ol> <li>Check the directory for new files</li> <li>For each file (can be parallelized): <ol> <li>Process</li> <li>Send email or notify your Django application </li> </ol></li> <li>Sleep for a while</li> </ol> <p>My project contains really CPU-demanding processing. I currently use an external process that gives processing jobs to a pool of worker processes (that's basically what Celery could do for you) and reports the progress and results back to the Django application via POST requests. It works really well and is relatively scalable, but I will soon change it to use Celery on a cluster.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload