@@ -108,41 +108,25 @@ Locking module
108
108
# Initialize the lock object:
109
109
# NOTE : this does not acquire a lock yet
110
110
client = etcd.Client()
111
- lock = client.get_lock( ' /customer1 ' , ttl = 60 )
111
+ lock = etcd.Lock(client, ' my_lock_name ' )
112
112
113
113
# Use the lock object:
114
- lock.acquire(timeout = 30 ) # returns if lock could not be acquired within 30 seconds
115
- lock.is_locked() # True
116
- lock.renew(60 )
117
- lock.release()
118
- lock.is_locked() # False
114
+ lock.acquire(blocking = True , # will block until the lock is acquired
115
+ lock_ttl = None ) # lock will live until we release it
116
+ lock.is_acquired() #
117
+ lock.acquire(lock_ttl = 60 ) # renew a lock
118
+ lock.release() # release an existing lock
119
+ lock.is_acquired() # False
119
120
120
121
# The lock object may also be used as a context manager:
121
122
client = etcd.Client()
122
- lock = client.get_lock(' /customer1' , ttl = 60 )
123
- with lock as my_lock:
123
+ with etcd.Lock(' customer1' ) as my_lock:
124
124
do_stuff()
125
- lock.is_locked () # True
126
- lock.renew( 60 )
127
- lock.is_locked() # False
125
+ my_lock.is_acquired () # True
126
+ my_lock.acquire( lock_ttl = 60 )
127
+ my_lock.is_acquired() # False
128
128
129
129
130
- Leader Election module
131
- ~~~~~~~~~~~~~~~~~~~~~~
132
-
133
- .. code :: python
134
-
135
- # Set a leader object with a name; if no name is given, the local hostname
136
- # is used.
137
- # Zero or no ttl means the leader object is persistent.
138
- client = etcd.Client()
139
- client.election.set(' /mysql' , name = ' foo.example.com' , ttl = 120 , timeout = 30 ) # returns the etcd index
140
-
141
- # Get the name
142
- print (client.election.get(' /mysql' )) # 'foo.example.com'
143
- # Delete it!
144
- print (client.election.delete(' /mysql' , name = ' foo.example.com' ))
145
-
146
130
Get machines in the cluster
147
131
~~~~~~~~~~~~~~~~~~~~~~~~~~~
148
132
0 commit comments