Home Python multiple loops at the same time
Reply: 0

Python multiple loops at the same time

user903 Published in June 25, 2018, 4:08 am

I know that it is not possible to run multiple loops at the same time in Python. Anyhow, what I need to achieve is that I have one loop running reading loads of sensor data, every 0.25 seconds. At the same time I have signal devices running in parallel that need to send signals every 3 seconds. My question is what way is best practice to achieve this?

Does it make sense to write two scripts and run them in parallel? Does it make sense to use threading? Is there any other possibility in order to make this work?

I would be greatful for code samples.

Thank you!

Edit: Both loops are absolutely independent. So, let's say while script 1 is running, reading the sensor data, when one of the sensors received a value < 300, it should run script 2 which will send the signals. At the same time when the sensors data gets > 300 it should stop script 2.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305619 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO