I am working on a Python/bottle app that has two components:
In production, the two will be run in separate processes, but I'd like to run them both in the same process when running locally for development purposes.
Threading seems like the obvious answer, but threading is unnecessary when running the components in separate processes.
Is there an elegant way to optionally employ a threaded approach only when running both components in the same process?
This should not be a problem since it sounds like they are completely isolated. I would just add a new script that imports threading and then either wraps the other starter scripts in functions or calls the functions they use with the new threads.
Here is a simple example:
import threading
def script1():
import script1
def script2():
import script2
t1 = threading.Thread(target=script1)
t2 = threading.Thread(target=script2)
t1.start()
t2.start()
t1.join()
t2.join()
That would start anything in the scripts main section of the scripts, more ideally if the script had an actual main function you could run that in the threads.
A few things to note:
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments