views:

38

answers:

1

Is it possible to have a server side program that queues and manages processes that are executed at the command line?

The project I am working on takes an image from the user, modifies the image then applies it as a texture to a 3D shape. This 3D scene is generated by blender/Cinema 4d at the command line which outputs it as an image. It is this process that needs to be queued or somehow managed from the server side program. The end result sent back to the user is a video containing an animated 3D shape with their image as a texture applied to it.

These renders may take a while (they may not) but how can I ensure that they are executed at the right times and done so in a queued manner?

This will preferably be done in python.

+1  A: 

Lacking more details about how/why you're doing queuing (can only run so many at a time, things need to be done in the right order, etc?), it's hard to suggest a specific solution. However, the basic answer for any situation is that you want to use the subprocess module to fire off the processes, and then you can watch them (using the tools afforded to you by that module) to wait until they're complete and then execute the next one in the queue.

Nick Bastin
Because the process is 3D rendering, I need to ensure that if the system is sluggish then there is the possibility of queuing processes. I imagine 50 parallel renders would crash the system or have some sort of negative effect. The subprocess modules seems like exactly what I need. With a bit more detail on how I need it to run, do you still think subprocess is the right choice?
betamax
Absolutely - you can decide based on your system how many you think you can run at a time and then just queue up requests when you've reached that limit and service them once the previous renders complete. (You could also do more exotic things like query the system for CPU and memory utilization and decide if it's a good idea to start more processes, but that's independent of the `subprocess` module.. :-))
Nick Bastin