title: Interrupt all asyncio.sleep currently executing
body: <h3>where</h3>
  
  <p>This is on Linux, Python 3.5.1.</p>
  
  <h3>what</h3>
  
  <p>I'm developing a monitor process with <code>asyncio</code>, whose tasks at various places <code>await</code> on <code>asyncio.sleep</code> calls of various durations.</p>
  
  <p>There are points in time when I would like to be able to interrupt all said <code>asyncio.sleep</code> calls and let all tasks proceed normally, but I can't find how to do that. An example is for graceful shutdown of the monitor process.</p>
  
  <h3>how (failed assumption)</h3>
  
  <p>I thought that I could send an ALRM signal to that effect, but the process dies. I tried catching the ALRM signal with:</p>
  
  <pre><code>def sigalrm_sent(signum, frame):
      tse.logger.info("got SIGALRM")
  
  signal.signal(signal.SIGALRM, sigalrm_sent)
  </code></pre>
  
  <p>Then I get the log line about catching SIGALRM, but the <code>asyncio.sleep</code> calls are not interrupted.</p>
  
  <h3>how (kludge)</h3>
  
  <p>At this point, I replaced all <code>asyncio.sleep</code> calls with calls to this coroutine:</p>
  
  <pre><code>async def interruptible_sleep(seconds):
      while seconds &gt; 0 and not tse.stop_requested:
          duration = min(seconds, tse.TIME_QUANTUM)
          await asyncio.sleep(duration)
          seconds -= duration
  </code></pre>
  
  <p>So I only have to pick a <code>TIME_QUANTUM</code> that is not too small and not too large either.</p>
  
  <h3>but</h3>
  
  <p>Is there a way to interrupt all running <code>asyncio.sleep</code> calls and I am missing it?</p>