Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing Argument Errors
#1
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:

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
Reply


Messages In This Thread
Passing Argument Errors - by cosmarchy - Sep-27-2021, 07:47 PM
RE: Passing Argument Errors - by deanhystad - Sep-27-2021, 08:45 PM
RE: Passing Argument Errors - by cosmarchy - Sep-27-2021, 09:03 PM
RE: Passing Argument Errors - by deanhystad - Sep-27-2021, 09:23 PM
RE: Passing Argument Errors - by Yoriz - Sep-27-2021, 09:25 PM
RE: Passing Argument Errors - by cosmarchy - Sep-28-2021, 08:19 PM
RE: Passing Argument Errors - by snippsat - Sep-29-2021, 06:09 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Passing argument from top-level function to embedded function JaneTan 2 2,309 Oct-15-2020, 03:50 PM
Last Post: deanhystad
  SyntaxError: positional argument follows keyword argument syd_jat 3 5,922 Mar-03-2020, 08:34 AM
Last Post: buran
  Passing an argument by reference Exsul 12 4,850 Aug-22-2019, 07:29 AM
Last Post: DeaD_EyE
  passing an argument to avoid a global Skaperen 9 3,977 Jul-12-2019, 11:07 PM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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