Sep-27-2021, 07:47 PM
I have a simple(ish) program which is supposed to start a thread which will start two periodic processes.
The roughed out code I'm using to get started is this:
What am I doing wrong?
Thanks
The roughed out code I'm using to get started is this:
import threading import time import vlc import sys import schedule exitFlag = 0 class myThread (threading.Thread): def __init__(self, threadID, name): threading.Thread.__init__(self) self.threadID = threadID self.name = name def run(self): print("Starting " + self.name) schedule.every(5).seconds.do(self.every5sec, self.name) schedule.every(10).seconds.do(self.every10sec, self.name) while 1: schedule.run_pending() time.sleep(1) print("Exiting " + self.name) #not sure this will ever be called??? def every5sec(threadName): print("\n%s: %s" % (threadName, time.ctime(time.time()))) #do summit... def every10sec(threadName): print("\n%s: %s" % (threadName, time.ctime(time.time()))) #do summit... # Create new threads thread1 = myThread(1, "Thread-1") thread1.daemon=True # Start new Threads thread1.start() while 1: time.sleep(1)The thread starts ok but after 5 seconds, I get this error:
Output:PS D:\Desktop\Python Test> & C:/Users/cos/AppData/Local/Programs/Python/Python39/python.exe "d:/Desktop/Python Test/MultiThreardingTiming.py"
Starting Thread-1
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Users\cos\AppData\Local\Programs\Python\Python39\lib\threading.py", line 973, in _bootstrap_inner
self.run()
File "d:\Desktop\Python Test\MultiThreardingTiming.py", line 21, in run
schedule.run_pending()
File "C:\Users\cos\AppData\Local\Programs\Python\Python39\lib\site-packages\schedule\__init__.py", line 780, in run_pending
default_scheduler.run_pending()
File "C:\Users\cos\AppData\Local\Programs\Python\Python39\lib\site-packages\schedule\__init__.py", line 100, in run_pending
self._run_job(job)
File "C:\Users\cos\AppData\Local\Programs\Python\Python39\lib\site-packages\schedule\__init__.py", line 172, in _run_job
ret = job.run()
File "C:\Users\cos\AppData\Local\Programs\Python\Python39\lib\site-packages\schedule\__init__.py", line 661, in run
ret = self.job_func()
TypeError: every5sec() takes 1 positional argument but 2 were given
My understanding of the do function, is that the first argument self.every5sec
was the function and the second argument self.name
was the arguments for that function however this does not appear to be the case.What am I doing wrong?
Thanks