So I am using subprocess to spawn a long running process through the web interface using Django. Now if a user wants to come back to the page I would like to give him the option of terminating the subprocess at a later stage.
How can do this? I implemented the same thing in Java and made a global singleton ProcessManager dictionary to store the Process Object in Memory. Can I do something similar in Python?
EDIT
Yes Singletons and a hash of ProcessManager is the way of doing it cleanly. Emmanuel’s code works perfectly fine with a few modifications.
Thanks
I think an easy way to implement Singleton pattern in python is via class attributes:
Then you can use this class via:
Notes:
ProcessManageris in charge of creating the process, to be symmetrical with its ending