I have something like this:
class thread1(threading.Thread):
def __init__(self):
file = open("/home/antoni4040/file.txt", "r")
data = file.read()
num = 1
while True:
if str(num) in data:
clas = ExportToGIMP
clas.update()
num += 1
thread = thread1
thread.start()
thread.join()
And I get this error:
TypeError: start() takes exactly 1 argument (0 given)
Why?
thread = thread1needs to bethread = thread1(). Otherwise you’re trying to call methods on the class, rather than an actual instance of the class.Also, don’t override
__init__on a Thread object to do your work – overriderun.(While you can override
__init__to do setup, that’s not actually run in a thread, and needs to callsuper()as well.)Here’s how your code should look: