How can you pass additional args to a worker function?

Heads up! You've already completed this tutorial.

Bhuvan | 2020-05-10 21:25:01 UTC | #1

How to pass the additional args and kwargs in execute_this_fn below is my code

python
worker = Worker(lambda :self.execute_this_fn(arg1, arg2, kwarg1)

I am getting

python
TypeError: <lambda>() got an unexpected keyword argument 'progress_callback'

pvn | 2020-05-10 21:09:54 UTC | #2

Have u got a chance to figured this out? I have the same problem.

Because I have an error when I'm passing parameters to function like this:

python
worker = Worker(self.execute_this_fn, param1, param2)

Error is:

The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]

python
TypeError: execute_this_fn() got multiple values for argument 'progress_callback'

anonymous | 2020-05-10 21:13:13 UTC | #3

Hi, i have experimented quite a lot with the classes and QThreadPool concepts in this tutorial. By far the best i could find on the topic!.

In your slot function, you must add a **kwargs whether you plan to emit the signal or not, because the progress_callback is added as a keyword argument automatically in the Worker __init__

Check it out:

python
class Worker(QRunnable):
...
def  **init** (self,
self.kwargs['progress_callback'] = self.signals.progress

Colin_Wu | 2020-05-11 11:45:51 UTC | #4

Sorry coming late to this party but here's what I found works (so far):

change execute_this_fn signature:

python
def exec_this_fn(self, progress_callback, start=0):
for n in range(start, 5):

Then in the oh_no function, change worker initiation to

python
worker = Worker(self.execute_this_fn, start=2)

In this trivial example, the "start" parameter lets me start the count from 2 rather than 0.

Hope this helps.


Bhuvan | 2020-05-11 11:56:38 UTC | #5

Thank you for your reply, Your answer was much helpful, I am facing new problem please can you help me? I have pyqtgraph window inside my QDialog, i am calling the QDialog from my mainwindow application (through Worker thread), some times the QDialog runs proprely, some times the whole GUI is crashes with out giving any error message. If i wont run the QDialog from Worker thread the QDialog will freeze until the task in completed.

My final intention is to run the sub window (QDialog) in thread, with out being freeze.


Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

How can you pass additional args to a worker function? was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.