The protection of resources

Hi !

In this time I use the Lock() for thread synchronization, and resource

protection.

But in the new project I must reorganize this thing.
The program must be run in lin/win, so I cannot use the winapi.

I need to protect resources from concurrent r/w.
Possible that the modules are not threads but are tasks.

In the Delphi and WinAPI I use the Mutex, that is a simple, opsystem
protected thing to signaling.
It is a simple signal (1/0).

I search for this in python, but I see only mutex with "procedure
queue".
I cannot see a signal like thing.
I want to only signaling: the resource are taken or not.
I don't want to wait for the non used state (not block !).

So these my questions:
- 1. How to use the py mutex object ? Please send an example to me !
- 2. Have the py an signal object ? (platform !!!)
- 3. Is any solution is a file locking. Have the py a possibility of
exclusive
file opening ?

Thx:
KK

Krisztian Kepes wrote:

In this time I use the Lock() for thread synchronization, and resource
protection.

But in the new project I must reorganize this thing.
The program must be run in lin/win, so I cannot use the winapi.

I need to protect resources from concurrent r/w.
Possible that the modules are not threads but are tasks.

Hm. Sharing a resource between threads is pretty easy -- set up a threading.Thread that handles all access to a given resource, and pass requests and responses to that thread through a pair of Queue.Queue's. The queues will handle all thread-synchronization for you, and can be used in either blocking or non-blocking modes.

Sharing resources across processes is a more complex matter. I'm no expert on inter-process communication, but there are several options -- shared memory, sockets, and pipes (FIFO files) being the main ones. I'm not sure if there's any support for shared memory in Python, but sockets and pipes can definitely be used. Depending on your requirements, you might be able to set up a multithreaded socketserver to manage a given resource and have client processes connect to that. Thanks to Python's "batteries included", a simple socketserver could be done in as little as a few dozen lines, or modified from one of the many utilities available from the Vaults of Parnassus (http://www.vex.net/parnassus).

Jeff Shannon
Technician/Programmer
Credit International