3 ms·
It's an extremely common bug in basically all languages that allow closures to capture "live" variables. Almost every developer that uses any kind of async prog
by OskarS 10y ago
It's an extremely common bug in basically all languages that allow closures to capture "live" variables. Almost every developer that uses any kind of async programming gets bit by it eventually. For-loops and closures do not mix well.
- deleted 10y ago[deleted]
- xapata 10y agoThe author did not create any closures in the example code. Python only creates a closure for a def in a def. Regardless, using functools.partial solves that problem: ``callback = partial(print, i)``.