title: python asyncio.Event.wait() not responding to event.set()
body: <p>The plan is to have several IO routines running "concurrently" (specifically on a Raspberry Pi, manipulating IO pins and running an SPI interface at the same time). I try to use asyncio to make this happen. However, my simple try-out refuses to run.<br>
  This is a reduced version of the code, leaving out the IO pin details:</p>
  
  <pre><code>"""\
  Reduced problem representation:
  this won't run because GPIO details have been left out
  """
  
  import RPi.GPIO as gpio
  import asyncio
  
  GPIO_PB = 12         # Define pushbutton channel
  
  async def payload():
      """ Provides some payload sequence using asyncio.sleep() """
      #Payload action
      await asyncio.sleep(1)
      #Payload action
      await asyncio.sleep(1)
  
  class IOEvent(asyncio.locks.Event):
      """\
      Create an Event for asyncio, fired by a callback from GPIO
      The callback must take a single parameter: a gpio channel number
      """
      def __init__(self, ioChannel, loop):
          super().__init__(loop = loop)
          self.io = ioChannel
  
      def get_callback(self):
          "The callback is a closure that knows self when called"
          def callback( ch ):
              print("callback for channel {}".format(ch))
              if ch == self.io and not self.is_set():
                  print(repr(self))
                  self.set()
                  print(repr(self))
          return callback
  
  async def Worker(loop, event):
      print("Entering Worker: {}".format(repr(loop)))
      while loop.is_running():
          print("Worker waiting for {}".format(repr(event)))
          await event.wait()
          print("Worker has event")
          event.clear()
          await payload()
          print("payload ended")
  
  loop = asyncio.get_event_loop()
  
  # Create an event for the button
  pb_event = IOEvent( GPIO_PB, loop)
  
  # register the pushbutton's callback
  # Pushing the button calls this callback function
  gpio.add_event_callback( GPIO_PB, pb_event.get_callback() )
  
  try:
      asyncio.ensure_future(Worker(loop, pb_event))
      loop.run_forever()
  except KeyboardInterrupt:
      pass
  finally:
      print("Closing Loop")
      loop.stop()
      loop.close()
  </code></pre>
  
  <p>The output I get is like this:</p>
  
  <pre><code>Entering Worker: &lt;_UnixSelectorEventLoop running=True closed=False debug=False&gt;
  Worker waiting for &lt;__main__.IOEvent object at 0x76a2a950 [unset]&gt;
  callback for channel 12
  &lt;__main__.IOEvent object at 0x76a2a950 [unset,waiters:1]&gt;
  &lt;__main__.IOEvent object at 0x76a2a950 [set,waiters:1]&gt;
  callback for channel 12
  </code></pre>
  
  <p>These lines show the pushbutton repeatedly and correctly firing its callback routine. The first time it calls the <code>set()</code> funtion as expected. The event used for the <code>wait()</code> call and the <code>set()</code> call are the same. But the message <em>"Worker has event"</em>, after the <code>await event.wait()</code> call never appears.</p>
  
  <p>I looked at <a href="https://stackoverflow.com/questions/32141623/pyqt5-and-asyncio-yield-from-never-finishes?s=1%7C60.2233">PyQt5 and asyncio: yield from never finishes</a>, but I do not see any other loops than the default loop.</p>
  
  <p>Why does <code>wait()</code> never return? How could I find out?</p>