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

What do you mean by "threadsafe" here? Could dict.items() actually break in Python 2? I've never seen that happen.


As I admitted in my comment, I'm not 100% sure that it's not protected by the GIL. If it's not, I wouldn't expect a hard crash if you mutate from another thread while iterating, but more like e.g. an item doesn't appear in the even though a different one had been removed by the other thread. But as I said in my comment, even if it does happen to be protected by the GIL, I think it's unsafe and fragile to rely on it.


Unexpected/undefined behavior?


There are a lot of cases when you don't need strict consistency and current state is enough for processing. For example you want to save requests stats from web servers. Would you stop all operations until you counting and writing to DB to be precise? Off course not. Some current number that you have is good enough for you. Off course you need to be aware of side effects.




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

Search: