I have a worker object, which has many functions and I'll like to use them on an extra thread. So, I followed this answer and it works if I pass a fixed number of arguments to the functions, more or less like this:
_signalCommand = QtCore.pyqtSignal(str, str)
self._signalCommand.connect(self.nanomax.test)
self._signalCommand.emit('testA', 'testB')
But in my case, I can't use a fixed number of arguments. I need optional ones, my functions are like this:
def test(self, test1='test1', test2='test2'):
print test1
print test2
So, in order to fix that I was using lambda, like this:
_signalCommand = QtCore.pyqtSignal()
self._signalCommand.connect(lambda: self.nanomax.test('testA', 'testB')
self._signalCommand.emit()
Doing this way, indeed, fix my optional arguments problems but it makes the object running in the main thread. I think this is because lambda creates another function and is like calling the worker directly (self.nanomax.test('testA', 'testB'
) as mentioned in the answer I previously shared.
Is there anyway to avoid this? Thank you in advance.