Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 run two tasks concurrently
Hello, I just got a Pi, that what motivated me to learn Python. I am a absolute newbies when it come to python programming,  I joint this forum.

I am making an app I have a script to read data to Pi with serial from sensors in Aduino,
It is a very simple script:
import serial, time

ser = serial.Serial('/dev/ttyUSB0', 9600)

while True :
   data = ser.readline()
   print str(data)
now besides reading data. the Pi also control the a timed relay relay to turn things on and off, so I made a timer script:
import RPi.GPIO as GPIO
import time

while True: 
   print ("LED on")
   time.sleep(1) # Insert here?
   print ("LED off")
   time.sleep(1) # Insert here?

Now my trouble is (conciliate the two scripts into one) keeping the timer running while reading data concurrently. How does python do that? Do I need to create a a dedicated thread to run them or is there a sinpler way to do it. Thanks.
A couple of things to look at:
I would suggest three processes, running the timer separately and
notifying the other processes as required.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Watching for inputs from multiple sources concurrently anakaine 4 460 Mar-03-2019, 07:38 PM
Last Post: woooee
  How to add asynchronous tasks as they are needed? AlekseyPython 2 437 Jan-11-2019, 02:58 AM
Last Post: AlekseyPython
  How I can limit quantity of parallel executable tasks in asyncio? AlekseyPython 1 582 Oct-24-2018, 10:22 AM
Last Post: AlekseyPython
  reading 2 files concurrently Skaperen 3 786 Jun-01-2018, 07:07 AM
Last Post: Skaperen
  Python - Make Json objects to work concurrently through Threads? WeInThis 0 1,128 Sep-22-2017, 11:31 AM
Last Post: WeInThis
  Tasks for Python Lamon112 2 1,511 Jan-13-2017, 03:32 AM
Last Post: metulburr

Forum Jump:

Users browsing this thread: 1 Guest(s)