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
#1
Hi,

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.

Thanks

oz
Reply
#2
This is my answer.
>>> for _ in range(5):
...     __import__('random').choice(['Script', 'Computer', 'Some thing else'])
...     
'Script'
'Computer'
'Script'
'Some thing else'
'Script'
So Script it is,it can look like a joke answer,but based on information you have given it's not Think
Reply
#3
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()
        pass
        
    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 = datetime.datetime.now()
            current_date = current_datetime.strftime('%d-%m-%Y')
            if(input_date>=current_date):
                while(True):
                    _time = datetime.datetime.now()
                    current_time= _time.strftime('%H:%M:%S')
                    if(input_time==current_time):
                        #self.mouse.position = (1912,594)
                        #self.mouse.click(Button.left,1)
                        #time.sleep(2)
                        self.mouse.position = (1250,710)
                        self.mouse.click(Button.left,1)
                        time.sleep(2)
                        self.mouse.position = (1824,1136)
                        self.mouse.click(Button.left,1)
                        time.sleep(2)
                        self.mouse.position = (1587,37)
                        self.mouse.click(Button.left,1)
                        time.sleep(2)
                        self.mouse.position = (1250,710)
                        self.mouse.click(Button.left,1)
                        time.sleep(2)
                        #self.mouse.position = (1202, 806)
                        #self.mouse.click(Button.left,1)
                        print("streaming........")
                        time.sleep(int(input_duration)*60)#please put your streaming function 
                        self.mouse.position = (1824,1136)
                        self.mouse.click(Button.left,1)
                        break
                    elif(input_time>current_time):
                        print('Waiting for the next stream to start at {}'.format(input_time)+" hrs on {}".format(input_date))
                        time.sleep(1)
                        continue
                    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))
                        time.sleep(1)
                        continue
                    else:
                        break
                else:
                    pass
                    
        time_file.close()
        _msg = "All streaming task finished"
        return _msg

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




start_streaming = Autostreaming().startstreaming()
Reply
#4
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pip stops waiting for python walker 6 966 Nov-28-2023, 06:55 PM
Last Post: walker
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,003 Jun-29-2023, 11:57 AM
Last Post: gologica
  [SOLVED] [Linux] Script in cron stops after first run in loop Winfried 2 894 Nov-16-2022, 07:58 PM
Last Post: Winfried
  Know when the pyttsx3 engine stops talking UsualCoder 3 3,138 Aug-29-2021, 11:08 PM
Last Post: snippsat
  email timer/rss feed timer ndiniz 1 2,040 Feb-02-2021, 07:18 PM
Last Post: nilamo
  IDLE stops responding upon saving tompi1 2 1,888 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 5,787 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,247 May-28-2020, 05:27 PM
Last Post: micseydel
  Python stops without errors shahgourav 4 2,703 Feb-04-2020, 11:44 PM
Last Post: micseydel
  Package python script which has different libraries as a single executable or script tej7gandhi 1 2,581 May-11-2019, 08:12 PM
Last Post: keames

Forum Jump:

User Panel Messages

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