File tree Expand file tree Collapse file tree 2 files changed +9
-24
lines changed Expand file tree Collapse file tree 2 files changed +9
-24
lines changed Original file line number Diff line number Diff line change 1616# others who want to test things using xcffib.
1717
1818import errno
19+ import fcntl
1920import os
2021import subprocess
2122import time
@@ -30,32 +31,17 @@ def lock_path(display):
3031def find_display ():
3132 display = 10
3233 while True :
33- lock_file = lock_path (display )
34-
3534 try :
36- with open (lock_file , 'r' ) as f :
37- pid = int (f .read ().strip ())
38-
35+ f = open (lock_path (display ), "w+" )
3936 try :
40- os .kill (pid , 0 )
41- display += 1
42- continue
43- except (OSError , ProcessLookupError ):
44- try :
45- os .remove (lock_file )
46- except FileNotFoundError :
47- pass
48-
49- except (FileNotFoundError , ValueError , OSError ):
50- pass
51-
52- try :
53- fd = os .open (lock_file , os .O_CREAT | os .O_EXCL | os .O_WRONLY , 0o644 )
54- os .write (fd , str (os .getpid ()).encode ())
55- return display , fd
56- except FileExistsError :
37+ fcntl .flock (f .fileno (), fcntl .LOCK_EX | fcntl .LOCK_NB )
38+ except OSError :
39+ f .close ()
40+ raise
41+ except OSError :
5742 display += 1
5843 continue
44+ return display , f
5945
6046
6147class XvfbTest :
@@ -117,7 +103,7 @@ def tearDown(self):
117103 # clean up after itself.
118104 try :
119105 os .remove (lock_path (self ._display ))
120- os . close ( self ._display_lock )
106+ self ._display_lock . close ( )
121107 except OSError as e :
122108 # we don't care if it doesn't exist, maybe something crashed and
123109 # cleaned it up during a test.
Original file line number Diff line number Diff line change @@ -38,5 +38,4 @@ xcffib = ["py.typed"]
3838[project .optional-dependencies ]
3939dev = [
4040 " pytest>=8.4" ,
41- " pytest-xdist" ,
4241]
You can’t perform that action at this time.
0 commit comments