Python Forum
Python timer script stops before should
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python timer script stops before should

I have a script that starts and is supposed to run for a pre determined time set out in a txt file, like this.. first one 2.55 pm and run for 50 mins then stop and start again at the 6.55 etc.

30-04-2020 14:55:00 50
30-04-2020 18:55:00 50
30-04-2020 09:55:00 50
01-04-2020 02:55:00 50
01-04-2020 09:55:00 50

It used to work fine but now, it starts on time, runs for a while but then stops, say in 10 mins or so. It doesn't do the 50 minutes length.

Could this be a script problem (although it has been good), or maybe a computer problem.
Appreciate your thoughts.


This is my answer.
>>> for _ in range(5):
...     __import__('random').choice(['Script', 'Computer', 'Some thing else'])
'Some thing else'
So Script it is,it can look like a joke answer,but based on information you have given it's not Think
This is the script..

import time
import datetime
import sys
from pynput.mouse import Button, Controller
class Autostreaming(object):

    def __init__(self):
        self.mouse = Controller()
    def startstreaming(self):
        #load text file 
        time_file = open("time.txt", "r")
        for date_time_duration in time_file.readlines():
            input_date,input_time,input_duration=date_time_duration.split(' ')
            current_datetime =
            current_date = current_datetime.strftime('%d-%m-%Y')
                    _time =
                    current_time= _time.strftime('%H:%M:%S')
                        #self.mouse.position = (1912,594)
                        self.mouse.position = (1250,710)
                        self.mouse.position = (1824,1136)
                        self.mouse.position = (1587,37)
                        self.mouse.position = (1250,710)
                        #self.mouse.position = (1202, 806)
                        time.sleep(int(input_duration)*60)#please put your streaming function 
                        self.mouse.position = (1824,1136)
                        print('Waiting for the next stream to start at {}'.format(input_time)+" hrs on {}".format(input_date))
                    elif(input_date>current_date and input_time<current_time):
                        print('Waiting for the next stream to start at {}'.format(input_time)+" hrs on {}".format(input_date))
        _msg = "All streaming task finished"
        return _msg

    def stopstreaming(self):
        print("streaming stoped")
        return sys.exit()

start_streaming = Autostreaming().startstreaming()
Any help here please?

Is there anything in this script that would cause the stream to stop before the allocated time? For example the time.txt file has the time to start and run like this..
04-05-2020 09:30:00 40
04-05-2020 12:30:00 40
04-05-2020 15:30:00 40
04-05-2020 22:30:00 40
When I run the the stream manually not using the script, it runs the full 40 mins length however as soon as I use the script, it stops the stream a few minutes in. It is not any specific time, just a random time.

I see my two options are..
something in the script or
something going on in the PC background, although it doesn't do it when I don't use the script.

Please help and I am not sure where else to go as it does seem like a script or python event.

Thank you

Possibly Related Threads…
Thread Author Replies Views Last Post
  email timer/rss feed timer ndiniz 1 393 Feb-02-2021, 07:18 PM
Last Post: nilamo
  IDLE stops responding upon saving tompi1 2 448 Oct-01-2020, 05:44 PM
Last Post: Larz60+
  How to kill a bash script running as root from a python script? jc_lafleur 4 1,183 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 743 May-28-2020, 05:27 PM
Last Post: micseydel
  Python stops without errors shahgourav 4 961 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 1,090 May-11-2019, 08:12 PM
Last Post: keames
  First for loop stops after first iteration Divanova94 10 3,613 May-01-2019, 04:27 PM
Last Post: buran
  Python Thread stops execution neethuvp 1 1,214 Feb-18-2019, 06:36 PM
Last Post: micseydel
  randint stops changing values in a loop Naito 4 1,352 Jan-30-2019, 08:15 AM
Last Post: perfringo
  detect when scanner stops darter 1 1,164 Jun-29-2018, 10:07 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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