Try to avoid OSError [errno 22] in Android triggered by fp.truncate(0)
This commit is contained in:
parent
beb15d9b77
commit
973f39d5b2
|
@ -52,21 +52,18 @@ class singleinstance:
|
||||||
self.lockfile,
|
self.lockfile,
|
||||||
os.O_CREAT | os.O_EXCL | os.O_RDWR | os.O_TRUNC
|
os.O_CREAT | os.O_EXCL | os.O_RDWR | os.O_TRUNC
|
||||||
)
|
)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
type, e, tb = sys.exc_info()
|
|
||||||
if e.errno == 13:
|
if e.errno == 13:
|
||||||
print(
|
sys.exit(
|
||||||
'Another instance of this application'
|
'Another instance of this application'
|
||||||
' is already running'
|
' is already running'
|
||||||
)
|
)
|
||||||
sys.exit(-1)
|
|
||||||
print(e.errno)
|
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
pidLine = "%i\n" % self.lockPid
|
pidLine = "%i\n" % self.lockPid
|
||||||
os.write(self.fd, pidLine)
|
os.write(self.fd, pidLine)
|
||||||
else: # non Windows
|
else: # non Windows
|
||||||
self.fp = open(self.lockfile, 'a+')
|
self.fp = open(self.lockfile, 'wb+')
|
||||||
try:
|
try:
|
||||||
if self.daemon and self.lockPid != os.getpid():
|
if self.daemon and self.lockPid != os.getpid():
|
||||||
# wait for parent to finish
|
# wait for parent to finish
|
||||||
|
@ -75,11 +72,11 @@ class singleinstance:
|
||||||
fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
fcntl.lockf(self.fp, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||||
self.lockPid = os.getpid()
|
self.lockPid = os.getpid()
|
||||||
except IOError:
|
except IOError:
|
||||||
print 'Another instance of this application is already running'
|
sys.exit(
|
||||||
sys.exit(-1)
|
'Another instance of this application is already running')
|
||||||
else:
|
else:
|
||||||
pidLine = "%i\n" % self.lockPid
|
pidLine = "%i\n" % self.lockPid
|
||||||
self.fp.truncate(0)
|
self.fp.truncate()
|
||||||
self.fp.write(pidLine)
|
self.fp.write(pidLine)
|
||||||
self.fp.flush()
|
self.fp.flush()
|
||||||
|
|
||||||
|
@ -98,7 +95,7 @@ class singleinstance:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return
|
return
|
||||||
print "Cleaning up lockfile"
|
print('Cleaning up lockfile')
|
||||||
try:
|
try:
|
||||||
if sys.platform == 'win32':
|
if sys.platform == 'win32':
|
||||||
if hasattr(self, 'fd'):
|
if hasattr(self, 'fd'):
|
||||||
|
|
Reference in New Issue
Block a user