Skip to content

Commit 7e8ae57

Browse files
committed
Linux: add an error handler for the XServer to prevent interpreter crash
1 parent 7daaad7 commit 7e8ae57

File tree

8 files changed

+254
-78
lines changed

8 files changed

+254
-78
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ History:
22

33
<see Git checking messages for history>
44

5+
3.3.0 2018/08/xx
6+
- Linux: add an error handler for the XServer to prevent interpreter crash (fix #61)
7+
58
3.2.1 2018/05/21
69
- new contributor: Ryan Fox
710
- Windows: enable Hi-DPI awareness

CHANGES.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
3.3.0 (2018-08-xx)
2+
==================
3+
4+
exception.py
5+
------------
6+
- Added ``details`` attribute to ``ScreenShotError`` exception. Empty dict by default.
7+
8+
linux.py
9+
--------
10+
- Added ``error_handler()`` function
11+
12+
113
3.2.1 (2018-05-21)
214
==================
315

docs/source/api.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ GNU/Linux
2626

2727
See :meth:`mss.base.MSSBase.grab()` for details.
2828

29+
.. function:: error_handler(display, event)
30+
31+
:type display: ctypes.POINTER(Display)
32+
:param display: The display impacted by the error.
33+
:type event: ctypes.POINTER(Event)
34+
:param event: XError details.
35+
:return int: Always ``0``.
36+
37+
Error handler passed to `X11.XSetErrorHandler()` to catch any error that can happen when calling a X11 function.
38+
This will prevent Python interpreter crashes.
39+
40+
When such an error happen, a :class:`mss.exception.ScreenShotError` exception is raised and all XError information are added to the :attr:`mss.exception.ScreenShotError.details` attribute.
41+
42+
.. versionadded:: 3.3.0
2943

3044
Methods
3145
=======
@@ -231,6 +245,17 @@ Exception
231245

232246
Base class for MSS exceptions.
233247

248+
.. attribute:: details
249+
250+
On GNU/Linux, and if the error comes from the XServer, it contains XError details.
251+
This is an empty dict by default.
252+
253+
For Xerrors, you can find information on `Using the Default Error Handlers <https://tronche.com/gui/x/xlib/event-handling/protocol-errors/default-handlers.html>`_.
254+
255+
:rtype: dict[str, Any]
256+
257+
.. versionchanged:: 3.3.0
258+
234259

235260
Factory
236261
=======

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
# built documents.
3232
#
3333
# The short X.Y version.
34-
version = '3.2.1'
34+
version = '3.3.0'
3535

3636
# The full version, including alpha/beta/rc tags.
3737
release = 'latest'

mss/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from .exception import ScreenShotError
1414
from .factory import mss
1515

16-
__version__ = '3.2.1'
16+
__version__ = "3.3.0"
1717
__author__ = "Mickaël 'Tiger-222' Schoentgen"
1818
__copyright__ = """
1919
Copyright (c) 2013-2018, Mickaël 'Tiger-222' Schoentgen

mss/exception.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@
77

88
class ScreenShotError(Exception):
99
""" Error handling class. """
10+
11+
def __init__(self, message, details=None):
12+
# type: (Dict[str, Any]) -> None
13+
super(Exception, self).__init__(message)
14+
self.details = details or dict()

0 commit comments

Comments
 (0)