Projet

Général

Profil

Lock24 » Historique » Version 5

Emmanuel GARETTE, 11/12/2012 15:38

1 1 Emmanuel GARETTE
h1. Lock24
2 1 Emmanuel GARETTE
3 1 Emmanuel GARETTE
h2. Fonctionnement sur 2.3
4 1 Emmanuel GARETTE
5 1 Emmanuel GARETTE
Il existe plusieurs bibliothèques python de gestion des locks :
6 1 Emmanuel GARETTE
7 1 Emmanuel GARETTE
* creole/eolelock.py
8 1 Emmanuel GARETTE
* pyeole/lock.py
9 2 Emmanuel GARETTE
* /usr/share/eole/eolelock.py
10 2 Emmanuel GARETTE
* FonctionEoleNg : *Lock
11 3 Emmanuel GARETTE
* /usr/lib/python2.6/dist-packages/zephir/lib_zephir.py
12 1 Emmanuel GARETTE
13 1 Emmanuel GARETTE
La première appelle la seconde. Elles font quasiment la même chose.
14 1 Emmanuel GARETTE
15 1 Emmanuel GARETTE
Le lock est mis avec la commande "touch".
16 2 Emmanuel GARETTE
17 2 Emmanuel GARETTE
h2. Utilisations :
18 2 Emmanuel GARETTE
19 2 Emmanuel GARETTE
h3. instance/reconfigure
20 2 Emmanuel GARETTE
21 2 Emmanuel GARETTE
Ne pas pouvoir faire d'instance/reconfigure si un autre lock connu est placé.
22 2 Emmanuel GARETTE
23 2 Emmanuel GARETTE
h3. ead
24 2 Emmanuel GARETTE
25 2 Emmanuel GARETTE
Savoir si une sauvegarde est lancée.
26 2 Emmanuel GARETTE
27 2 Emmanuel GARETTE
h3. zephir-client/data/scripts/import_aaf.zephir
28 2 Emmanuel GARETTE
29 2 Emmanuel GARETTE
A étudier.
30 2 Emmanuel GARETTE
31 2 Emmanuel GARETTE
h3. Bacula :
32 2 Emmanuel GARETTE
33 2 Emmanuel GARETTE
Placer un lock si aucun lock placé.
34 1 Emmanuel GARETTE
35 1 Emmanuel GARETTE
h2. Mise à jour 2.4
36 1 Emmanuel GARETTE
37 5 Emmanuel GARETTE
Objectif : supprimer toutes les bibliothèques pour utiliser pyeole/lock.py.
38 1 Emmanuel GARETTE
39 5 Emmanuel GARETTE
h3. Niveau de lock
40 5 Emmanuel GARETTE
41 5 Emmanuel GARETTE
* 'normal' : c'est un lock isolé pour une application simple ;
42 5 Emmanuel GARETTE
* 'system' : un lock system est exclusif, dès qu'une application met un lock system, les autres applications pourront le savoir.
43 5 Emmanuel GARETTE
44 5 Emmanuel GARETTE
h3. Pour place un lock
45 5 Emmanuel GARETTE
46 5 Emmanuel GARETTE
Il est possible de place un lock avec la fonction acquire. 
47 5 Emmanuel GARETTE
48 5 Emmanuel GARETTE
<pre>
49 5 Emmanuel GARETTE
>>> from pyeole.lock import acquire
50 5 Emmanuel GARETTE
>>> acquire('nom_du_lock')
51 5 Emmanuel GARETTE
</pre>
52 5 Emmanuel GARETTE
53 5 Emmanuel GARETTE
Une exception AlreadyLocked est renvoyé si le lock est déjà placé.
54 5 Emmanuel GARETTE
Pour ne pas vérifié la présence d'un lock ultérieur faire :
55 5 Emmanuel GARETTE
56 5 Emmanuel GARETTE
<pre>
57 5 Emmanuel GARETTE
>>> from pyeole.lock import acquire
58 5 Emmanuel GARETTE
>>> acquire('nom_du_lock', valid=False)
59 5 Emmanuel GARETTE
</pre>
60 5 Emmanuel GARETTE
61 5 Emmanuel GARETTE
Enfin, il est possible de spécifier le level avec l'attribut "level".
62 5 Emmanuel GARETTE
63 5 Emmanuel GARETTE
h3. Retirer un lock
64 5 Emmanuel GARETTE
65 5 Emmanuel GARETTE
Pour retirer un lock il faut utilise la fonction release.
66 5 Emmanuel GARETTE
67 5 Emmanuel GARETTE
<pre>
68 5 Emmanuel GARETTE
>>> from pyeole.lock import release
69 5 Emmanuel GARETTE
>>> release('nom_du_lock')
70 5 Emmanuel GARETTE
</pre>
71 5 Emmanuel GARETTE
72 5 Emmanuel GARETTE
Tout comme acquire, il est possible de ne pas faire d'erreur en cas de non présence du lock avec l'attribut valid.
73 5 Emmanuel GARETTE
74 5 Emmanuel GARETTE
Par contre, un lock placer par un autre thread/process ne pourra pas être retiré, sauf en faisant :
75 5 Emmanuel GARETTE
76 5 Emmanuel GARETTE
<pre>
77 5 Emmanuel GARETTE
>>> from pyeole.lock import release
78 5 Emmanuel GARETTE
>>> release('nom_du_lock', force=True)
79 5 Emmanuel GARETTE
</pre>
80 5 Emmanuel GARETTE
81 5 Emmanuel GARETTE
Enfin, il est possible de spécifier le level avec l'attribut "level".
82 5 Emmanuel GARETTE
83 5 Emmanuel GARETTE
h3. Tester les locks
84 5 Emmanuel GARETTE
85 5 Emmanuel GARETTE
Pour tester si un fichier lock est placé au niveau 'normal' :
86 5 Emmanuel GARETTE
87 5 Emmanuel GARETTE
<pre>
88 5 Emmanuel GARETTE
>>> from pyeole.lock import is_locked
89 5 Emmanuel GARETTE
>>> if is_locked('nom_du_lock'):
90 5 Emmanuel GARETTE
>>>     print "lock placé"
91 5 Emmanuel GARETTE
</pre>
92 5 Emmanuel GARETTE
93 5 Emmanuel GARETTE
Pour tester si un lock système existe :
94 5 Emmanuel GARETTE
95 5 Emmanuel GARETTE
<pre>
96 5 Emmanuel GARETTE
>>> from pyeole.lock import is_locked, get_system_lock
97 5 Emmanuel GARETTE
>>> if is_locked(level='system'):
98 5 Emmanuel GARETTE
>>>     print "lock system placé ", get_system_lock()
99 5 Emmanuel GARETTE
</pre>
100 5 Emmanuel GARETTE
101 5 Emmanuel GARETTE
Pour tester si un lock système a été placé par une autre application que la sienne :
102 5 Emmanuel GARETTE
103 5 Emmanuel GARETTE
<pre>
104 5 Emmanuel GARETTE
>>> from pyeole.lock import is_locked, get_system_lock
105 5 Emmanuel GARETTE
>>> if is_locked(level='system', name='nom_du_lock'):
106 5 Emmanuel GARETTE
>>>     print "lock system placé autre que ", name, get_system_lock(name)
107 5 Emmanuel GARETTE
</pre>