Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is the same as the solution from the article, except that:

- Chris forgot to declare the variable as global;

- Chris used asyncio.create_task() instead of asyncio.ensure_future().



Maybe it's me not grokking async, but the code seems right to me. `once` is a decorator, so `future` is "instantiated" once per decorated function, which is then accessed as nonlocal in the wrapper. So in the last code sample, every call to `one_time_setup()` is accessing the same `future`.


Thanks for pointing that out, for some reason I had thought the last implementation also used a lock.


(Chris has added the global declaration since then.)


Since D is not being rebound, the global declaration is unneeded.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: