There's something I've been looking for a long time to solve, and can't find.
How can I pass variables between python processes, without using Queue
or Pipe
?
import multiprocessing
string = "hi"
def my_process():
global string
string = "success!" # but its only localy...
multiprocessing.Process(target=my_process).start()
I am looking for a way to change a variable from different scripts or processes...
Finally,
I created a package for Python to solve this problem.
$ pip install guli
Guli doesn't require installing any additional PIP package.
Guli can be used to pass between different Python scripts, between many processes or at the same script. pass variables between main Process and another (Multiprocess) Process.
import guli
import multiprocessing
string = guli.GuliVariable("hello").get()
print(string) # returns empty string ""
def my_function():
''' change the value from another process '''
guli.GuliVariable("hello").setValue(4)
multiprocessing.Process(target=my_function).start()
import time
time.sleep(0.01) # delay after process to catch the update
string = guli.GuliVariable("hello").get()
print(string) # returns "success!!!"
Hope I solved the problem for many people!