PYTHON   66

python monitor a file for r changes and interrupt

Guest on 2nd May 2022 02:37:41 PM

  1. import time
  2. import fcntl
  3. import os
  4. import signal
  5. # python monitor a file for r changes and interrupt
  6. FNAME = "/app/tmp/"
  7.  
  8. def handler(signum, frame):
  9.     pass
  10. #    print "File %s modified" % (FNAME,)
  11.  
  12. signal.signal(signal.SIGIO, handler)
  13. fd = os.open(FNAME,  os.O_RDONLY)
  14. fcntl.fcntl(fd, fcntl.F_SETSIG, 0)
  15. fcntl.fcntl(fd, fcntl.F_NOTIFY,
  16.             fcntl.DN_MODIFY | fcntl.DN_CREATE | fcntl.DN_MULTISHOT)
  17.  
  18. print "sleeping..."
  19. time.sleep(20)
  20. print "waking up now"
  21. os.close(fd)

Raw Paste


Login or Register to edit or fork this paste. It's free.