Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 383972 Details for
Bug 519656
dev-util/catalyst: stage build fails if two instances of catalyst are run while using snapcache
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
POC: timeout if you wait on a lock too long
test_lock_crash.py (text/x-python), 1.59 KB, created by
Anthony Basile
on 2014-08-30 17:42:26 UTC
(
hide
)
Description:
POC: timeout if you wait on a lock too long
Filename:
MIME Type:
Creator:
Anthony Basile
Created:
2014-08-30 17:42:26 UTC
Size:
1.59 KB
patch
obsolete
>#!/usr/bin/python > >import os, sys, fcntl, time, signal > >lockfilename = "mylockfile" >crashfilename = "unclean_state" > > >def signal_handler(signal, frame): > print('I got tired of waiting') > sys.exit(0) > > >def do_lock(): > fd = os.open(lockfilename, os.O_CREAT|os.O_RDWR, 0o660) > > try: > fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB) > print("Got the lock first ... ", end='', flush=True) > except IOError as e: > signal.alarm(5) > print("Someone beat us to the lock") > fcntl.lockf(fd, fcntl.LOCK_EX) > signal.alarm(0) > print("Got the lock second ... ", end='', flush=True) > > if os.path.isfile(crashfilename): > print("in an unclean state!", flush=True) > print("Doing cleanup!", flush=True) > os.unlink(crashfilename) > else: > print("in an clean state!", flush=True) > > return fd > > >def do_it(): > for i in range(1,6): > print('.', end='', flush=True) > time.sleep(1) > print(' crash me! ', end='', flush=True) > for i in range(1,6): > print('.', end='', flush=True) > time.sleep(1) > print(flush=True) > > >def do_unlock(fd): > fcntl.lockf(fd, fcntl.LOCK_UN) > time.sleep(1) > > try: > fcntl.lockf(fd, fcntl.LOCK_EX|fcntl.LOCK_NB) > os.close(fd) > os.unlink(lockfilename) > except IOError as e: > os.close(fd) > > >def main(): > signal.signal(signal.SIGALRM, signal_handler) > fd = do_lock() > try: > do_it() > except: > print('I crashed!') > os.close(os.open(crashfilename, os.O_CREAT|os.O_RDWR, 0o660)) > do_unlock(fd) > > >if __name__ == "__main__": > main()
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 519656
:
382972
| 383972