title: Is there a python library for notification and waiting?
body: <p>I'm using python-zookeeper for locking, and I'm trying to figure out a way of getting the execution to wait for notification when it's watching a file, because <code>zookeeper.exists()</code> returns immediately, rather than blocking.</p>
  
  <p>Basically, I have the code listed below, but I'm unsure of the best way to implement the <code>notify()</code> and <code>wait_for_notification()</code> functions. It could be done with <code>os.kill()</code> and <code>signal.pause()</code>, but I'm sure that's likely to cause problems if I later have multiple locks in one program - is there a specific Python library that is good for this sort of thing?</p>
  
  <pre><code>def get_lock(zh):
      lockfile = zookeeper.create(zh,lockdir + '/guid-lock-','lock', [ZOO_OPEN_ACL_UNSAFE], zookeeper.EPHEMERAL | zookeeper.SEQUENCE)
  
      while(True):
          # this won't work for more than one waiting process, fix later
          children = zookeeper.get_children(zh, lockdir)
          if len(children) == 1 and children[0] == basename(lockfile):
              return lockfile
  
          # yeah, there's a problem here, I'll fix it later
          for child in children:
              if child &lt; basename(lockfile):
                  break
  
          # exists will call notify when the watched file changes
          if zookeeper.exists(zh, lockdir + '/' + child, notify):
              # Process should wait here until notify() wakes it
              wait_for_notification()
  
  
  def drop_lock(zh,lockfile):
      zookeeper.delete(zh,lockfile)
  
  def notify(zh, unknown1, unknown2, lockfile):
      pass
  
  def wait_for_notification():
      pass
  </code></pre>