On Thu, Mar 5, 2009 at 3:46 AM, Philip Jenvey <[email protected]> wrote: > > > On Mar 4, 2009, at 1:58 PM, kgs wrote: > >> >> I could not find anywhere unambigous answer if accessing Python >> primitives from many threads is safe or not - for me it looks that it >> might be not safe (because modyfing/iterating/accessing e.g. >> dictionary may result in context switches). > > This is the most authoritative page: > > http://effbot.org/pyfaq/what-kinds-of-global-value-mutation-are-thread-safe.htm > > It's still a bit ambiguous on what is really safe, but I can guarantee > the two basic dict operations in question (a getitem and setitem on > steady dict value) are in fact safe. >
Yeah, this site is a bit ambigous, e.g. "Operations that replace other objects may invoke those other objects’ __del__ method when their reference count reaches zero, and that can affect things. This is especially true for the mass updates to dictionaries and lists. When in doubt, use a mutex!" But before that statement author said that following operations are atomic: D[x] = y D1.update(D2) where x,y are objects and D1 and D2 are dict. So how this could be true? But even if we assume that getitem and setitem on dict are atomic (on 'steady' value only? which means primitives?). How to solve problem which I am facing now: I want to start another thread T1 in my Pylons App (manually, not Paste#http worker) and have some global dict which all http workers will read. But T1 periodically will update this dictionary (in fact all he want to do is to swap this global dict with local dict which was prepared during his work). In this dict I will have Python primitives (other dicts too) and simple classes which act only as 'structs'. Do I need lock? Cheers, Kamil Gorlo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en -~----------~----~----~----~------~----~------~--~---
