Reputation: 699
In my Python (3.6) program, I have a thread object, like so:
class MyThread(threading.Thread):
def __init__(self):
super(MyThread, self).__init__()
...
def __del__(self):
...
super(type(self), self).__del__()
def run(self):
...
used in the main program like this:
def main():
my_thread = MyThread()
my_thread.start()
...
my_thread.join()
But as soon as I try to run this program, I get the following Python crash:
Exception ignored in: <bound method MyThread.__del__ of <MyThread(Thread-6, stopped 1234)>>
Traceback (most recent call last):
File "c:/my_proj/my_program.py", line 123, in __del__
super(type(self), self).__del__()
AttributeError: 'super' object has no attribute '__del__'
Why is this, and how can it be fixed?
Is it not allowed to call the __del__()
method of super explicitly like this, or what? (Google seems to tell me otherwise, but still won't give me any answer to why this happens)
Upvotes: 1
Views: 7323
Reputation: 1
My original function in original model has no "api.model", but in my inherited function I was using it, this was creating the error. that "enroll_student() expected 1 argument, but 2 were given, I removed api.model, and the error went away.
Upvotes: 0
Reputation: 1
I was getting an AttributeError
because I did not use @api.model
before my method in which I was calling the original method to be overriden.
Upvotes: -1
Reputation: 137517
super(type(self), self)
is always wrong. In Python 2, you must explicitly name the current class, e.g. super(MyThread, self)
. In Python 3, you can simply use super()
:
class MyThread(threading.Thread):
def __init__(self):
super().__init__()
# ...
def run(self):
# ...
That said, if if the superclass has no __del__
then you'll get this AttributeError
. If your base classes have no __del__
you can simply omit it. There is rarely a good reason to implement __del__
in your class.
If you need controlled cleanup, consider using implementing a context manager.
Upvotes: 4