Error:
TypeError: scrape_child_link() missing 1 required positional argument: 'failure'
When I get to the following part in my code the above happens.
class A(object):
def start(self):
....
kill = threading.Event()
# starting here
child_link_thread = threading.Thread(target=ThreadExecutioner.execute_child,args=(self.scrape_child_link, child_link_queue, self.site, code_io_handle, text_io_handle, kill)).start()
....
@staticmethod
def scrape_child_link(self, link: str, used_children: Queue, site: StackOverflow, code_io_handle, text_io_handle,failure: threading.Event):
....
class ThreadExecutioner():
@staticmethod
def execute_child(target: callable(object), tasks: Queue, site: source, code_io_handle, text_io_handle,kill: threading.Event):
parent_threader = threading.Thread(target=target,args=(task, hit_queue, site, code_io_handle,text_io_handle, kill),daemon=True)
parent_threader.start() #Exception thrown here
Ive stepped through this and all of the variables are set by the time the second thread is dispatched. But for some reason the thread does not recognize the
kill
variable
Have you tried passing self as the first argument? I know that seems strange since it's automatic, but passing a method into a thread could disassociated the method and self. If that fixes it, the problem would be that it's applying the arguments to each parameter and coming up one short.
Edit: On a related note, you should probably refactor so you aren't passing a method. I imagine that's a thread safety issue.
(Jun-17-2020, 10:33 PM)stullis Wrote: [ -> ]Have you tried passing self as the first argument? I know that seems strange since it's automatic, but passing a method into a thread could disassociated the method and self. If that fixes it, the problem would be that it's applying the arguments to each parameter and coming up one short.
Edit: On a related note, you should probably refactor so you aren't passing a method. I imagine that's a thread safety issue.
That did not solve the issue. I'm trying to migrate some code someone else wrote to a new project, so refactoring is not desired.
Okay, I looked at it again. There's a problem with the number of parameters and arguments.
The args passed to ThreadExecutioner.execute_child() contains six values. The first value is scrape_child_link() which has six parameters as well; this leaves only five arguments to be passed into scrape_child_link(). Based on the variable names provided, it seems the link parameter of scrape_child_link() has no argument when ThreadExecutioner.execute_child() calls scrape_child_link().
So, ThreadExecutioner.execute_child() requires an additional argument to properly run scrape_child_link().