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
  Know when the pyttsx3 engine stops talking UsualCoder 3 376 Aug-29-2021, 11:08 PM
Last Post: snippsat
  email timer/rss feed timer ndiniz 1 725 Feb-02-2021, 07:18 PM
Last Post: nilamo
  IDLE stops responding upon saving tompi1 2 713 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,856 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 963 May-28-2020, 05:27 PM
Last Post: micseydel
  Python stops without errors shahgourav 4 1,188 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,350 May-11-2019, 08:12 PM
Last Post: keames
  First for loop stops after first iteration Divanova94 10 4,586 May-01-2019, 04:27 PM
Last Post: buran
  Python Thread stops execution neethuvp 1 1,520 Feb-18-2019, 06:36 PM
Last Post: micseydel
  randint stops changing values in a loop Naito 4 1,681 Jan-30-2019, 08:15 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

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