ParthS007/background

Extra arguments when calling a task.

Closed this issue · 5 comments

Well done with the great module.

Is it possible to call the task with extra arguments? When I tried I get the following error.

TypeError:do_task() takes 0 positional arguments but 1 was given

For this code snippet:

@background.task
def work(*args):
    time.sleep(1)
    print("inside", str(args[0]))

for i in range(5):
    work(i)

I'm having the same problem. When I comment out the @background.task decorator the code works. When the decorator is uncommented I get the following error.

TypeError: do_task() takes 0 positional arguments but 1 was given

Having a decorator for running background tasks is an awesome idea.

I got around this by creating a nested function:

def work(*args):

  @background.task
  def run():
    time.sleep(1)
    print("inside", str(args[0]))

  run()

But this feature would be nice to have!

fruch commented

this have an example doing similar with args and kwargs...(and it's a nice package anyhow)
https://github.com/lord63/py-spin/blob/master/pyspin/spin.py

ned2 commented

This might be fixed by #6, which passes args and kwargs through to the function being backgrounded.

@NikosVlagoidis I think your problem is fixed now after merging of #6
Please don't hesitate to open a new issue if you face any other problem.
Thanks