1

Not really a coding question, but one for understanding the python language. The apply_async function (from multiprocessing library) has one pass arguments to the function with something that looks like this:

result = pool.apply_async(some_func, (argument1,))

Why does the function require passing arguments with (argument1, ), requiring a comma before an empty argument? I understand tuples, but what's with the empty argument?

Thanks!

  • Can you clarify what you mean by "comma before an empty argument"? There are two arguments being passed, namely ``some_func`` and ``(argument1,)`` and neither are empty. Are you asking why it is ``(argument1,)`` instead of ``(argument1)``? – MisterMiyagi Nov 30 '20 at 08:18
  • 2
    Does this answer your question? [What is the syntax rule for having trailing commas in tuple definitions?](https://stackoverflow.com/questions/7992559/what-is-the-syntax-rule-for-having-trailing-commas-in-tuple-definitions) – MisterMiyagi Nov 30 '20 at 08:20

1 Answers1

2

That is a tuple with only one element. You could also pass more arguments inside this tuple so the method requires a tuple. If you only have one argument, you need a single element tuple

Alexander Riedel
  • 1,329
  • 1
  • 7
  • 14