Is extending a Python list (e.g. l += [1]) guaranteed to be thread-safe?
If I have an integer i , it is not safe to do i += 1 on multiple threads: >>> i = 0 >>> def increment_i(): ... global i ... for j in range(1000): i += 1 ... >>> threads = [threading.Thread(target=increment_i) for j in range(10)] >>> for thread in threads: thread.start() ... >>> for thread in threads: thread.join() ... >>> i 4858 # Not 10000 However, if I have a list l , it does seem safe to do l += [1] on multiple threads: >>> l = [] >>> def extend_l(): ... global l ... for j in range(1000): l += [1] ... >>> threads = [threading.Thread(target=extend_l) for j in range(10)] >>> for thread in