0

is there any way I can run python code in this way:

main code will run all the time , once every 5 min will run another function while running the main code.

my code is reading gps signal and send it to my server every 5 seconds.

I have to run another code that check the device cpu\file\temp every 5 min (this part take around 30 seconds ) can both of them run at the same time while still getting gps?

I have the GPS code ready and also the Check code ready - how do I combine them (if it's possiable)

Thanks ,

  • Yes, they can. Just start two different python processes from different terminals (as the simplest way) – roganjosh Aug 25 '20 at 15:07

3 Answers3

0

This might answer your question: Running Two Script at Once Using Bash

Based on the answer here, all you'd have to run is:

python script1.py &
python script2.py &
lime
  • 801
  • 8
  • 21
0

You can use the threading module, to do this task: it allows you to run functions as different processes seperate from the main program. Threading Documentation

0

I think you should get what you want with the following code:

import threading


def gpsJob():
    threading.Timer(300.0, gpsJob).start()
    # Here goes your GPS-code


gpsJob()

if __name__ == '__main__':
    # main code
ph140
  • 478
  • 3
  • 10