Python Forum
I got a problem with python schedule
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I got a problem with python schedule
#1
Hi im trying to make an time triggered event with schedule where i can inpute a time and then activate the clock after a couple of seconds something would happen but my code is giving me an error.

Error:
Traceback (most recent call last): File "C:\Users\xzenon\Desktop\timmer\time2.py", line 29, in ok_handler schedule.every(sekunderValue).seconds.do(self.job) File "C:\Users\xzenon\AppData\Local\Programs\Python\Python37-32\lib\site-packages\schedule\__init__.py", line 393, in do self._schedule_next_run() File "C:\Users\xzenon\AppData\Local\Programs\Python\Python37-32\lib\site-packages\schedule\__init__.py", line 428, in _schedule_next_run self.period = datetime.timedelta(**{self.unit: interval}) TypeError: unsupported type for timedelta seconds component: str
So what am i doing wrong?

Here is my code.

import sys
import schedule
 
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import QApplication, QPushButton, QLineEdit
from PySide2.QtCore import QFile, QObject
 
class Form(QObject):
 
    def __init__(self, ui_file, parent=None):
        super(Form, self).__init__(parent)
        ui_file = QFile(ui_file)
        ui_file.open(QFile.ReadOnly)
 
        loader = QUiLoader()
        self.window = loader.load(ui_file)
        ui_file.close()
 
        self.sekunder = self.window.findChild(QLineEdit, 'sekunder')
 
        btn = self.window.findChild(QPushButton, 'pushButton')
        btn.clicked.connect(self.ok_handler)
        self.window.show()
 
    def ok_handler(self):
        sekunderValue = self.sekunder.text()
        
        print(sekunderValue)
        schedule.every(sekunderValue).seconds.do(self.job)
        
        while 1:
           schedule.run_pending()
           time.sleep(1)
           
        
    def job(self):
       print("I'm working...")
       
if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = Form('timmer.ui')
    sys.exit(app.exec_())
Reply
#2
So, the traceback shows that the method call on line 29 ultimately results in an error because a string has been passed instead of an integer. From what I see, the suspect variable you're passing in is "sekunderValue" which is set on line 26:

sekunderValue = self.sekunder.text()
The method .text() suggests to me that it returns a string. If that is intended to be an integer, you need to do this instead for the ok_handler method:

    def ok_handler(self):
        sekunderValue = int(self.sekunder.text())
         
        print(sekunderValue)
        schedule.every(sekunderValue).seconds.do(self.job)
         
        while 1:
           schedule.run_pending()
           time.sleep(1)
Reply
#3
Thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Cancelling previous schedule cosmarchy 2 2,735 Sep-15-2021, 04:55 PM
Last Post: Larz60+
  Hosting a script on a VPS, and on a schedule? oldguy 0 2,918 Mar-13-2021, 02:46 AM
Last Post: oldguy
  something i noticed about the "schedule" module Stan2292 1 1,740 Aug-30-2019, 06:04 AM
Last Post: buran
  How to schedule Jupyter Notebooks with Papermill wendysling 0 2,478 Jun-11-2019, 05:53 PM
Last Post: wendysling
  schedule module conundrum wgovideo 11 4,240 May-29-2019, 06:39 PM
Last Post: wgovideo
  Schedule with other processing RValentim 7 3,938 Jul-10-2018, 12:57 PM
Last Post: RValentim
  How to convert Schedule to APScheduler module? penguin9 2 3,727 May-03-2018, 12:44 PM
Last Post: penguin9
  Creating a schedule program ndplokkaar 4 3,902 Nov-23-2017, 04:21 PM
Last Post: ndplokkaar

Forum Jump:

User Panel Messages

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