Python Forum
Python timer script stops before should - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Python timer script stops before should (/thread-26422.html)



Python timer script stops before should - ozstar - May-01-2020

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


RE: Python timer script stops before should - snippsat - May-01-2020

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


RE: Python timer script stops before should - ozstar - May-01-2020

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()



RE: Python timer script stops before should - ozstar - May-04-2020

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