title: Python threads and linux ioctl wait
body: <p>I have the following toy example for Python threading module</p>
  
  <pre><code>from __future__ import print_function
  import threading
  import time
  import signal
  import sys
  import os
  import time
  
  class ThreadShutdown(Exception):
      # Custom exception to allow clean thread exit
      pass
  
  def thread_shutdown(signum, frame):
      print(" o Signal {} caught and raising ThreadShutdown exception".format(signum))
      raise ThreadShutdown
  
  def main():
  
      """
      Register the signal handlers needed to stop 
      cleanly the child accessing thread
      """
      signal.signal(signal.SIGTERM, thread_shutdown)
      signal.signal(signal.SIGINT, thread_shutdown)
  
      test_run_seconds = 120
  
      try:
          thread = ChildThread()
          thread.start()
          time.sleep(1)
          while test_run_seconds &gt; 0:
              test_run_seconds -= 1
              print(" o [{}] remaining time is {} seconds".format(time.asctime( time.localtime(time.time()) ), test_run_seconds))
              time.sleep(1)
  
      except ThreadShutdown:
          thread.shutdown_flag.set()
          thread.join()
          print(" o ThreadShutdown procedure complete")
          return
  
      proc.terminate()
      thread.shutdown_flag.set()
      thread.join()
      print(" o Test terminated")
  
  class ChildThread(threading.Thread):
  
      def __init__(self):
          threading.Thread.__init__(self)
          self.shutdown_flag = threading.Event()
  
      def run(self):
  
          while not self.shutdown_flag.is_set(): 
              print(" o [{}] is the current time in child, sleep for 10s".format(time.asctime( time.localtime(time.time()))))
              time.sleep(10)
  
          return
  
  if __name__ == "__main__":
      sys.exit(main())
  </code></pre>
  
  <p>which behaves as expected (the main thread counts every second while the spawned thread prints only every 10 seconds.</p>
  
  <p>I was trying to understand the behaviour of the same code snippet in presence of blocking waits in kernel mode in the spawned thread. For example, assume that the spawned thread now goes into a killable wait in an ioctl with a timeout of 10s, I would still expect to have the main thread counting every second. For some reason, it instead counts every 10s, as if it was blocked as well in the wait of the spawned thread. What is the reason?</p>