Python Forum
how to stop and start a script for 30 seconds
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to stop and start a script for 30 seconds
#4
schedule work fine for this.
You could probably do all in Python,and drop the the shell script.
Here a example of making a file then delete,run_sh example on how to call shell script with subprocess.
import schedule
import time, os
import subprocess

def make_file():
    fn = 'test.out'
    open(fn, 'a').close()
    print(f'Making <{fn}>')

def del_file():
    try:
        fn ='test.out'
        os.remove(fn)
        print(f"Removed <{fn}>")
    except FileNotFoundError:
        print(f'Could not find <{fn}>')

def run_sh():
    '''Example running shell script'''
    subprocess.run(['bash', 'start.sh'])

schedule.every(8).seconds.do(make_file)
schedule.every(12).seconds.do(del_file)
while True:
    schedule.run_pending()
    time.sleep(1)
Output:
λ python remove_file.py Making <test.out> Removed <test.out> Making <test.out> Removed <test.out> Making <test.out> Making <test.out> Removed <test.out> Making <test.out>
Reply


Messages In This Thread
RE: how to stop and start a script for 30 seconds - by snippsat - Jan-14-2020, 04:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Button to stop while loop from another script Absolutewind 5 947 Sep-25-2023, 11:20 PM
Last Post: deanhystad
  ''.join and start:stop:step notation for lists ringgeest11 2 2,459 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  Problem with module time and leap seconds Pedroski55 3 1,270 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  non-stop ping script kucingkembar 1 1,376 Aug-23-2022, 06:29 AM
Last Post: menator01
  readline.parse_and_bind() does not work in start-up script of Python interpreter zzzhhh 0 1,542 Jan-18-2022, 11:05 AM
Last Post: zzzhhh
  Store variable data and display sum after 60 seconds the_dude 11 3,491 Dec-16-2021, 07:07 PM
Last Post: deanhystad
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,576 Sep-27-2021, 05:40 PM
Last Post: rondon442
  How to calculate time difference between each row of dataframe in seconds Mekala 1 2,590 Jul-16-2020, 12:57 PM
Last Post: Larz60+
  Looking for help on making a script [no idea where to start] Chietnemese 1 1,777 Jun-26-2020, 03:50 AM
Last Post: Larz60+
  How can I stop the script when I run the game on my own computer? StatTark 2 2,249 Jun-19-2020, 11:20 AM
Last Post: StatTark

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020