Alex Rivera | Logout

Asynchronous background processes with web2py

Asked 2011-12-29T13:20:04.907
8

I need to to handle a large (time and memory-consuming) process asynchronously in a web2py application called inside a controller method.

My specific use case is to call a process via stdlib.subprocess and wait for it to exit without blocking the web server, but I am open to alternative methods.

  • Hands-on examples would be a plus.
  • 3rd party library recommendations are welcome.
  • CRON scheduling is not required/wanted.
Edit
Report

1 Answer

1

This is more difficult than one might expect. Note the deadlock warnings in the stdlib.subprocess documentation. It's easy if you don't mind blocking---use Popen.communicate. To work around the blocking, you can manage the process using stdlib.subprocess from a thread.

My favorite way to deal with subprocesses is to use Twisted's spawnProcess. But, it is not easy to get Twisted to play nicely with other frameworks.

answered 2011-12-29T13:38:33.977

Your Answer