IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 2 LpH | Statistics
Login | Create New User

Welcome to IWETHEY!

New Python, threads, mutexes... how?
Lazy SOB that I am, I come again seeking help getting Python to do what I want. I want to have a bunch of threads that put keys in a dictionary, and another thread that enumerates the same dictionary from time to time. naturally, I want to wrap the dictionary with a mutex.

I've figured out how to spawn threads, but I can't yet wrap my head around how the mutexes work in Python. I've googled and come up with nothing useful. Some sample code would be nice.

(The closest I've come is some recommendation to use event queues to talk between threads. That's a kluge. All my experience in real time work tells me not to use a queue without a damn good reason. It opens the door to queue backup and all its attendant horrors.)

Any pointers? Thanks in advance.
Everything's a mystery until you figure out how it works.
We are here to go!
The nihilists and the liars have buried truth alive in a shallow grave.
New Re: Python, threads, mutexes... how?

You create a lock object for the thing you wish to lock (in this case, a dictionary). Anytime you wish to access the dictionary, you attempt to acquire the lock first. When you are done using it, you release the lock.

I would suggest wrapping the dictionary (and the lock behavior) in an object so you don't have lock code all over the place.

-scott anderson

"Welcome to Rivendell, Mr. Anderson..."
     Python, threads, mutexes... how? - (marlowe) - (1)
         Re: Python, threads, mutexes... how? - (admin)

Over 9000!
41 ms