el envío de un formulario se bloquea hasta que finaliza el proceso inicializado

I have been writing some a django project / app that initiates some test scripts. I previously asked a question about how to do this here.. integrando scripts de python con django

I've hit a problem which I didn't think would happen. I have a form working, using jquery to display certain checkboxes that pass values which initiates an api to my application I am testing. Exactly like the code in my initial question. However, when I submit the form, the form hangs whilst the back end process finishes

submittest.initialise_test(t_start, t_templatename, t_datacenter)

return render_to_response('testsubmitted.html')

I know I could use a popen or cron, however I have written my app and it would take some re-engineering.

Any ideas how I could make the submittest.initialise_test(t_start, t_templatename, t_datacenter) an asynchronous call or a way to get round this issue?. The results get written to a database, which I was then hoping to use to render to a results page using ajax to update the results.

preguntado el 29 de agosto de 12 a las 09:08

You can try spawning new thread docs.python.org/library/thread.html#module-thread -

Thanks - I've been reading up on this.. I just don;t want any spawned threads that are left open but I will definitely consider this.. could be an easy option -

Actually this worked and I didn't use a message queue in the end. All I did was import thread, then change the submittest.intialise_test(t_start, t_templatename, t_datacenter) to thread.start_new_thread(submittest.intialise_test, (t_start, t_templatename, t_datacenter)) -

glad! that seemed easiest approach if you don't want to monitor,manipulate the thread/task. -

1 Respuestas

Puedes usar uno de los muchos django background queue apps to run a task in a background process.

Respondido 29 ago 12, 10:08

yeah I thought of that. I'll have a look and see what options there are.. I have a feeling it will be a big rewrite of the app though - Aceite

Well I don't know your code so I can't say ... but if it's clean then you should find a quick way. Don't try to put much code in task definitions, rather, try to make tasks call code that's properly factored out in your app (so that you can use that code both with and without a task). - jpic

sure - thanks for the advice. My app is around 7000 lines of code. I have used classes to define different functions and have split these classes up in apps in django. Ie, api calls in one app, forms and views in another app, db calls in another app. But to summarise all these calls in to a question is fairly hard to do. However, the calls to the apis is where I need initiate the tasks so maybe its not going to be that bad after all. I'll just place these tasks in a queue an poll for the result.. Well that's the theory - Aceite

This is what I am going to use.. huey.readthedocs.org/en/latest/getting-started.html. If I struggle, i will repost a new question.. Thanks! - Aceite

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.