schrodinger.infra.exception_handler module

A top level Python exception handler that prevents uncaught exceptions in Python scripts from crashing Maestro.

To activate the exception handler use exception_handler.set_exception_handler(). That will activate the appropriate exception handler.

If SCHRODINGER_DEV_DEBUG or SCHRODINGER_SRC are defined, we install a handler that simply prints tracebacks to the terminal. Otherwise (generally on customer machines), we install a handler that writes uncaught exceptions to a folder in .schrodinger. The user is informed of the error and told to contact customer service.

class schrodinger.infra.exception_handler.ExceptionRecorder

Bases: object

A top level exception handler that writes uncaught exceptions to a folder in .schrodinger. The user is informed of the error and told to contact customer service.

This handler can be activated by sys.excepthook = ExceptionRecorder() or by calling the enable_handler() convenience function.

Variables:
  • _OPENFLAGS (int) – The flags used when opening a file. These flags are set to ensure that files are opened in a thread-safe manner.
  • _EXCEPTIONS_DIR (str) – The directory where exceptions are stored
  • _MAX_EXCEP_FILES (int) – The maximum number of files allowed in the exceptions directory. Once this number of files is hit, the oldest files will be erased after recording the next exception.
__init__()

Initialize self. See help(type(self)) for accurate signature.

__call__(etype, value, tb)

Write the specified exception to disk and print a helpful error message to the user. If anything goes wrong while recording the exception, print both the original exception and the new error to stderr.

Parameters:
  • etype (type) – The exception type
  • value (BaseException) – The exception that was raised
  • tb (traceback) – The traceback that led to the exception
__class__

alias of builtins.type

__delattr__

Implement delattr(self, name).

__dict__ = mappingproxy({'__module__': 'schrodinger.infra.exception_handler', '__doc__': '\n A top level exception handler that writes uncaught exceptions to a folder in\n .schrodinger. The user is informed of the error and told to contact\n customer service.\n\n This handler can be activated by `sys.excepthook = ExceptionRecorder()` or\n by calling the `enable_handler()` convenience function.\n\n :cvar _OPENFLAGS: The flags used when opening a file. These flags are set\n to ensure that files are opened in a thread-safe manner.\n :vartype _OPENFLAGS: int\n\n :cvar _EXCEPTIONS_DIR: The directory where exceptions are stored\n :vartype _EXCEPTIONS_DIR: str\n\n :cvar _MAX_EXCEP_FILES: The maximum number of files allowed in the\n exceptions directory. Once this number of files is hit, the oldest files\n will be erased after recording the next exception.\n :vartype _MAX_EXCEP_FILES: int\n ', '_OPENFLAGS': 193, '_EXCEPTIONS_DIR': '/home/buildbot/.schrodinger/exceptions', '_MAX_EXCEP_FILES': 40, '_MAX_EXCEP_PER_SECOND': 50, '__init__': <function ExceptionRecorder.__init__>, '__call__': <function ExceptionRecorder.__call__>, '_recordException': <function ExceptionRecorder._recordException>, '_getMessage': <function ExceptionRecorder._getMessage>, '_getExcepFile': <function ExceptionRecorder._getExcepFile>, '_genFilename': <function ExceptionRecorder._genFilename>, '_createExcepDir': <function ExceptionRecorder._createExcepDir>, '_cleanupExcepDir': <function ExceptionRecorder._cleanupExcepDir>, '__dict__': <attribute '__dict__' of 'ExceptionRecorder' objects>, '__weakref__': <attribute '__weakref__' of 'ExceptionRecorder' objects>})
__dir__() → list

default dir() implementation

__eq__

Return self==value.

__format__()

default object formatter

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__init_subclass__()

This method is called when a class is subclassed.

The default implementation does nothing. It may be overridden to extend subclasses.

__le__

Return self<=value.

__lt__

Return self<value.

__module__ = 'schrodinger.infra.exception_handler'
__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

Return repr(self).

__setattr__

Implement setattr(self, name, value).

__sizeof__() → int

size of object in memory, in bytes

__str__

Return str(self).

__subclasshook__()

Abstract classes can override this to customize issubclass().

This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).

__weakref__

list of weak references to the object (if defined)

schrodinger.infra.exception_handler.get_exception_handler()

Returns the appropriate exception handler, depending on values in the user’s environment.

schrodinger.infra.exception_handler.set_exception_handler(handler=None)

Sets the appropriate top-level Python exception handler. We use one for customers and another for developers.

There is no effect if there is already a custom exception handler.