Vous devez avoir un compte Developpez.com et être connecté pour pouvoir participer aux discussions.

Identifiez-vous
Identifiant
Mot de passe
Mot de passe oublié ?
Créer un compte

Vous n'avez pas encore de compte Developpez.com ? L'inscription est gratuite et ne vous prendra que quelques instants !

Je m'inscris !

Developpez.com

Python

Choisissez la catégorie, puis la rubrique :

9.9. mutex — Mutual exclusion support — Python v2.6.2 documentation

9.9. mutex — Mutual exclusion support¶

Deprecated since version The: mutex module has been removed in Python 3.0.

The mutex module defines a class that allows mutual-exclusion via acquiring and releasing locks. It does not require (or imply) threading or multi-tasking, though it could be useful for those purposes.

The mutex module defines the following class:

class mutex.mutex¶

Create a new (unlocked) mutex.

A mutex has two pieces of state — a “locked” bit and a queue. When the mutex is not locked, the queue is empty. Otherwise, the queue contains zero or more (function, argument) pairs representing functions (or methods) waiting to acquire the lock. When the mutex is unlocked while the queue is not empty, the first queue entry is removed and its function(argument) pair called, implying it now has the lock.

Of course, no multi-threading is implied – hence the funny interface for lock(), where a function is called once the lock is acquired.

9.9.1. Mutex Objects¶

mutex objects have following methods:

mutex.test()¶
Check whether the mutex is locked.
mutex.testandset()¶
“Atomic” test-and-set, grab the lock if it is not set, and return True, otherwise, return False.
mutex.lock(function, argument)¶
Execute function(argument), unless the mutex is locked. In the case it is locked, place the function and argument on the queue. See unlock() for explanation of when function(argument) is executed in that case.
mutex.unlock()¶
Unlock the mutex if queue is empty, otherwise execute the first element in the queue.
Contacter le responsable de la rubrique Python

Partenaire : Hébergement Web