Hello,

I've been working on an application in Web2py for a while now and, for the 
most part, I've been able to find answers to my questions online. However, 
I am having trouble now trying to figure out if I can use Python 
multiprocessing along with the Scheduler in Web2py in the way that I need 
to do so.

Essentially, I have an application that, upon some specified user input, 
the application needs to run one or more resource-intensive calculations 
(which can take upwards of an hour to complete). That being said, all the 
calculations need to run in the background and the results need to be 
reported back to the user. To deal with running the calculations in the 
background, I have decided that I will use the Web2py built-in scheduler 
and to deal with the resource-intensive aspect of the problem I am using 
the Python multiprocessing Pool class so that the application can take 
advantage of the multiple cores in the server that the application will be 
running on.

Starting the calculations using the Scheduler and multiprocessing has been 
fairly painless. However, I lock a bunch of UI stuff so that the user can't 
make changes while the tests are running, and, since the tests take so 
long, another requirement is that the user has the ability to cancel all 
the calculations (if they've made a mistake or have changed their mind 
about waiting more time for the calculations to complete). The problem that 
I'm having is that I cannot figure out how to use Web2py to cancel these 
tests.

I understand that to end a task is not complicated, and that to terminate 
the worker processes using the Python multiprocessing module all I need to 
do is call Pool.terminate(). The reason I'm having trouble doing this is 
that I can't find any way to persistently store these Pool instances to 
access them from another request.

I have been considering that a potential solution may be using cache.ram, 
if that will allow me to store a dictionary of these Pool instances. 
However, I am open to any other potential solutions, like if there's 
another way to get back to the correct Pool instance, if there's another 
way to create a persistent global (like a Queue) that I can use to 
communicate with the workers, or any other potential solutions.

If I seem to have any misunderstandings or if I need to clarify anything 
more please let me know.

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to