say from the following class thread_1 calls the "f1" function and my goal is that this call makes a separate thread(e.g., thread_2) to call "f2" function. What I thought was similar to the following:
from threading import Thread
class obj (object):
def __init__(self):
self.thr = Thread(target=self.f2, args=())
self.thr.start()
def f2 (self):
print('something')
def f1 (self):
self.thr.run()
a = obj()
a.f1()
but this gave the following error:
862 try:
--> 863 if self._target:
864 self._target(*self._args, **self._kwargs)
AttributeError: 'Thread' object has no attribute '_target'
During handling of the above exception, another exception occurred:
AttributeErrorTraceback (most recent call last)
<ipython-input-40-384ee2f45fe4> in <module>
----> 1 a.f2()
<ipython-input-38-ce8946449d8c> in f2(self)
9
10 def f2 (self):
---> 11 self.thr.run()
/usr/lib/python3.6/threading.py in run(self)
866 # Avoid a refcycle if the thread is running a function with
867 # an argument that has a member that points to the thread.
--> 868 del self._target, self._args, self._kwargs
869
870 def _bootstrap(self):
AttributeError: _target