I have started working with threading and now I get an error on the function main(). I have made a very simplistic version of my code that reproduces this error. I have now tried a lot to fix this problem, however, I did not even understand it properly. The error obviously occurs because of the "self, enable=''. What could fix this and what causes it?
PS: There are posts with an error similar to this, but they all refer to super() being used inside a function.
The error is:
Exception in thread main:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
TypeError: main() takes at least 1 argument (0 given)
My code:
import threading
from time import sleep
number = 0
alive = True
class Server(object):
def main(self, enable=''):
self.enable = int(enable)
#here we have some loops that rely on the variables like "enable"
def background():
global number
while alive:
if number < 20:
number=number+1
print 'Number: {0}'.format(number)
sleep(1)
else:
print "20 seconds are over!"
break
a = threading.Thread(name='main', target=main)
b = threading.Thread(name='background', target=background)
a.start()
b.start()
while alive: #this is just to terminate early
try:
sleep(.1)
except KeyboardInterrupt:
alive = False
print 'Terminated!'