Skip to content

Commit a8291f1

Browse files
committed
Linux: minor optimization when checking for a X extension status
By moving the code not using the thread lock outside of the context manager.
1 parent 4484be8 commit a8291f1

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ See Git checking messages for full history.
66
- removed support for Python 3.8
77
- added support for Python 3.14
88
- Linux: fixed a threadding issue in `.close()` when calling `XCloseDisplay()` (#251)
9+
- Linux: minor optimization when checking for a X extension status (#251)
910
- :heart: contributors: @
1011

1112
## 9.0.2 (2024-09-01)

src/mss/linux.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,22 +352,22 @@ def close(self) -> None:
352352

353353
def _is_extension_enabled(self, name: str, /) -> bool:
354354
"""Return True if the given *extension* is enabled on the server."""
355-
with lock:
356-
major_opcode_return = c_int()
357-
first_event_return = c_int()
358-
first_error_return = c_int()
355+
major_opcode_return = c_int()
356+
first_event_return = c_int()
357+
first_error_return = c_int()
359358

360-
try:
359+
try:
360+
with lock:
361361
self.xlib.XQueryExtension(
362362
self._handles.display,
363363
name.encode("latin1"),
364364
byref(major_opcode_return),
365365
byref(first_event_return),
366366
byref(first_error_return),
367367
)
368-
except ScreenShotError:
369-
return False
370-
return True
368+
except ScreenShotError:
369+
return False
370+
return True
371371

372372
def _set_cfunctions(self) -> None:
373373
"""Set all ctypes functions and attach them to attributes."""

0 commit comments

Comments
 (0)