def verify_calling_thread(self, should_be_emulation, message=None):
        """Verify if the calling thread is or is not the emulation thread.

        This method can be called to make sure that an action is being taken
        in the appropriate context such as not blocking the event loop thread
        or modifying an emulate state outside of the event loop thread.

        If the verification fails an InternalError exception is raised,
        allowing this method to be used to protect other methods from being
        called in a context that could deadlock or cause race conditions.

        Args:
            should_be_emulation (bool): True if this call should be taking place
                on the emulation, thread, False if it must not take place on
                the emulation thread.
            message (str): Optional message to include when raising the exception.
                Otherwise a generic message is used.

        Raises:
            InternalError: When called from the wrong thread.
        """

        if should_be_emulation == self._on_emulation_thread():
            return

        if message is None:
            message = "Operation performed on invalid thread"

        raise InternalError(message)
Verify if the calling thread is or is not the emulation thread.

        This method can be called to make sure that an action is being taken
        in the appropriate context such as not blocking the event loop thread
        or modifying an emulate state outside of the event loop thread.

        If the verification fails an InternalError exception is raised,
        allowing this method to be used to protect other methods from being
        called in a context that could deadlock or cause race conditions.

        Args:
            should_be_emulation (bool): True if this call should be taking place
                on the emulation, thread, False if it must not take place on
                the emulation thread.
            message (str): Optional message to include when raising the exception.
                Otherwise a generic message is used.

        Raises:
            InternalError: When called from the wrong thread.