0

I want to share a variable between two already running scripts. Or even spit string from one script to another.

script_1.py:

sensor_status = "Nobody"
while 1:
 sensor_status = arduino.get_sensor_status()
 sleep(5)

script_2.py:

sensor_status = # realtime value from script_1
while 1:
 if sensor_status == "Nobody":
 pass
 else:
 alarm()
asked Mar 26, 2020 at 5:02
11
  • I think multithreading might work here Commented Mar 26, 2020 at 5:04
  • 1
    You should add a sleep() to script 2 or it will run at 100% CPU. Commented Mar 26, 2020 at 5:12
  • 1
    Then can you use, as @Sociopath suggested, the ` multithreading` module and use a pipe or a queue ? Commented Mar 26, 2020 at 5:22
  • 1
    Is the communication one-way or two-way? What kind of computer are the scripts running on? You could use the multiprocessing library. The docs have producer/consumer examples. You could also use something like MQTT. Commented Mar 26, 2020 at 5:26
  • 1
    Take a look at this article: Introduction to Multiprocessing in Python Commented Mar 26, 2020 at 5:30

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.