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

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.
[link|http://www.angelfire.com/ca3/marlowe/index.html|http://www.angelfir...e/index.html]
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?
[link|http://www.python.org/doc/current/lib/rlock-objects.html|Locks]

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.
Regards,

-scott anderson

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

This results in serious pain.
103 ms