Quote (cmetc1999 @ Mar 7 2021 03:00am)
i am not entirely certain what you're trying to do, but using Manager to share the variable will probably get you closer to where you want to be.
Code
from ctypes import c_char_p
from multiprocessing import Process, Manager
from time import sleep
def device_a(setting):
counter = 0
while True:
sleep(1)
counter += 1
print(f'device_a at {counter} received: {setting.value}')
if __name__ == '__main__':a
# use manager to share setting across processes
manager = Manager()
shared_setting = manager.Value(c_char_p, "") # defaults to empty string, can prompt earlier or do whatever
# process
Process(target=device_a, args=(shared_setting,)).start()
# main thread
while True:
setting = input('Enter a setting: ')
shared_setting.value = setting
Thanks, so far your posted code does what I need. I am trying to run independently some external devices (motors, sensors, ect.) on my rapsberry pi, and from time to time want be albe to change the settings. Tried google before, and it suggested multiprocessing, which is pretty new for me (I do programming, and projects for fun).
Maybe there are some other ways to do it more effectively... have to do some more research.