1

Having a Thread class that when it runs, it starts 2 threads each of witch has its own purpose and they communicate together using a Queue.

One of these threads spawns more threads to process some stuff, I know this might be a bad design but her is my code

class MyThread(Thread):
  def __init__(self):
    # stuff
    Thread.__init__(self)

  def run(self):
    # some code that start a thread, this one starts fine

    # another thread started here and went fine
    processing_thread = Thread(target=self.process_files())
    processing_thread.daemon = True
    processing_thread.start()
    # more code 

 def process_files(self):
    while True:

      # stuff
      self.publish(file)
      # stuff

 def publish(self, file):
   # more code
   if (condition):
     self.semaphore.acquire(blocking=True)
     # HERE IT BREAKS
     thread = Thread(target=self.process(), args=(satellite, time, )) 
     thread.daemon = True
     thread.start()

 def process(self, satellite, time):
    #interpreter does not reach here

I tried staring the thread with:

args=(satellite, time,)
args=(satellite, time)
args=(self, satellite, time,)
args=(self, satellite, time)

I always get the error message TypeError: process() takes exactly 3 arguments (1 given)

What am I missing, or is it even possible to pass arguments this way?

1
  • 1
    Try removing the brackets after self.process: thread = Thread(target=self.process, args=(satellite, time, )) Commented Oct 25, 2017 at 16:10

1 Answer 1

1

The first comment here is correct.

When you are constructing the thread

thread = Thread(target=self.process(), args=(satellite, time, ))

You are invoking process, not passing it as parameter. This means you are trying to pass the result of process() to the thread, not the function itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.