AhmedWas
AhmedWas

Reputation: 1277

Can list.append(foo) be not thread-safe?

I've used multi-threading a lot, while appending to the same list from different threads. Everything worked fine.

However, I'm getting a problem with list appending when the threads are like 70 threads or more. Appending in the last thread gets stuck for like 5 mins (the processor is not occubied at this time, maybe 10 %. So, it's not a hardware problem I would say). Then appending occurs successfully.

At this link, it says that list appending is thread-safe.

My question is: Can list appending ever become not thread safe?

Don't ask for a code or so. I just need a simple yes or no to my question. And if yes, kindly provide suggestions to fix that.

Upvotes: 3

Views: 4310

Answers (1)

Xiwei Wang
Xiwei Wang

Reputation: 356

list appending in python is thread safe.

For more details: what kinds of global value mutation are thread safe

You last thread gets stuck maybe due to other reason, for example: Memory allocating..

My first step to fix the stuck is use strace to trace the syscall.

And you can use gdb to print all threads' call stack too. Here is a wiki page: https://wiki.python.org/moin/DebuggingWithGdb

Upvotes: 1

Related Questions