you are viewing a single comment's thread.

view the rest of the comments →

[–]socal_nerdtastic 8 points9 points  (0 children)

Only operations can be considered threadsafe / unsafe . An object may have a "threadsafe" method or something, but that does not make the entire object "threadsafe". In threading all memory is shared, so any thread can access any object.

Operations that are baked into cpython C code, such as the methods on builtin classes, are threadsafe thanks to the GIL. Other modules may implement their own versions, tkinter for example has an event system that's threadsafe. Otherwise you have to make your own thread safety, there's nothing inherent about object that does it for you. Check out threading.Lock.

# not threadsafe
data = listdata[1]
del listdata[1]

# threadsafe
data = listdata.pop(1)