Difference between threading.local and protecting data with locks

J

juxstapose

Hello,

I have been develop a blocking socket application with threading. The
main thread handles connections and inserts them into python's
protected queue as jobs for the thread pool to handle.

There is not much information on threading.local except that it states
that in maintains variable uniqueness among multiple instances of the
same thread. I am assuming that it implements some sort of locking
functionality under the covers? Is it possible to run into a race
condition using threading.local?

In a non-blocking threaded socket receive handler is it better to use a
threading.local variable for writes or protect the write with a
lock.acquire/lock.release ?

I know the size of the incoming request so the receive handler finishes
when the max size is reached. However in case of network problems I
also have timeout functionality. Both of these behaviors require
writing to variables in a possible critical section.
What is the best way to handle writes in a multi-threaded non-blocking
receive handler?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top