kquick/Thespian

Thespian crash while using fakefs

Closed this issue · 3 comments

When using an actor system made with thespian in pytest, starting the supervisor while using the fakefs fixture make it crash without any error message.

There is likely to be a thespian.log file in $TMPDIR that may provide some additional logging. I'm not familiar with the fakefs fixture and without more details on what your setup is it is hard for me to conjecture what might be happening. If you can provide a minimal set of code that reproduces this issue I'd be happy to look into it further.

I've reproduced the error in an atomic test. This time an error is displayed, it was catched previously due to pytest.

The code of the test is

#!/usr/bin/env python3
import pyfakefs
from thespian.actors import ActorSystem
import logging
import sys


class ActorLogFilter(logging.Filter):
    """
    Log filter
    """
    def filter(self, record):
        """
        filter logs that was produced by actor
        """
        return 'actor_name' in record.__dict__


class NotActorLogFilter(logging.Filter):
    """
    Log filter
    """
    def filter(self, record):
        """
        filter logs that was not produced by actor
        """
        return 'actorAddress' not in record.__dict__





def test_thespian(fs):
    LOG_DEF = {
    'version': 1,
    'formatters': {
        'normal': {'format': '%(levelname)s::%(created)s::ROOT::%(message)s'},
        'actor': {'format': '%(levelname)s::%(created)s::%(actor_name)s::%(message)s'}},
    'filters': {
        'isActorLog': {'()': ActorLogFilter},
        'notActorLog': {'()': NotActorLogFilter}},
    'handlers': {
        'h1': {'class': 'logging.StreamHandler',
               'stream': sys.stdout,
               'formatter': 'normal',
               'filters': ['notActorLog'],
               'level': logging.DEBUG},
        'h2': {
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            'formatter': 'actor',
            'filters': ['isActorLog'],
            'level': logging.DEBUG}
    },
    'loggers': {'': {'handlers': ['h1', 'h2'], 'level': logging.DEBUG}}
    }

    self.system = ActorSystem(systemBase='multiprocQueueBase', logDefs=LOG_DEF)

And the error displayed by pytest is thespian.actors.InvalidActorAddress: ActorAddr-Q.ThespianQ is not a valid ActorSystem admin on thespian/system/multiprocCommon.py:114

Without the fakefs fixture the test pass.

The pyfakefs module documents that it does not work correctly with the multiprocessing module, and there are no plans to fix that. The multiprocX bases in Thespian use the multiprocessing module. This appears to be a pyfakefs issue and not a Thespian issue, so I'm closing this, but feel free to revisit this if you have more information.