It would be slightly more robust to try casting ``task`` as a list, and catch ``TypeError`` to know when it's not iterable. That way ``task`` can be any kind of iterable.

```
try:
  for item in list(task):
    do_stuff()
except TypeError:
  do_different_stuff()
```