无法删除lockfile

时间:2014-07-14 19:30:03

标签: python lockfile

我正在尝试使用zc.lockfile。我看到在与我的python脚本相同的目录中创建了一个lockfile,但是当我按下ctrl + C时,该文件不会被删除。我已经注册了一个回调,甚至已经测试了很长时间(不确定zc.lockfile是否会生成一个新线程并需要时间来完成)。

import os
import sys
import signal
import time
import zc.lockfile

program_lock = None

def onExitCodePressed(signal, frame):
  """Callback run on a premature user exit."""
  global program_lock
  print '\r\nYou pressed Ctrl+C'
  program_lock.close()
  time.sleep(5)
  sys.exit(0)

def main():
  signal.signal(signal.SIGINT, onExitCodePressed)

  if os.path.exists('myapp_lock'):
    print "\nAnother instance of the program is already running.\n"
    sys.exit(0)
  else:
    program_lock = zc.lockfile.LockFile('myapp_lock')

  while True:
    continue


if __name__ == '__main__':
  main()

0 个答案:

没有答案