<commit_before>"The ActorManager is the wrapper and support structure for an actual Actor instance."

import sys
import logging
import copy
from thespian.actors import *
from thespian.system.utilis import thesplog
from thespian.system.systemCommon import systemCommonBase
from thespian.system.addressManager import CannotPickleAddress
from thespian.system.transport import *
from thespian.system.messages.admin import *
from thespian.system.messages.status import Thespian_StatusReq, Thespian_ActorStatus
from thespian.system.messages import *
from thespian.system.messages.convention import NotifyOnSystemRegistration
from thespian.system.messages.logcontrol import SetLogging
from thespian.system.utilis import ExpiryTime, actualActorClass
from thespian.system.sourceLoader import loadModuleFromHashSource
from datetime import timedelta
from functools import partial


MAX_SHUTDOWN_DRAIN_PERIOD=timedelta(seconds=7)


class ActorManager(systemCommonBase):
    def __init__(self, childClass, transport, sourceHash, sourceToLoad,
                 parentAddr, adminAddr,
                 childRequirements, currentSystemCapabilities):
        super(ActorManager, self).__init__(adminAddr, transport)
        self._parentAddr = parentAddr
        self._sourceHash = sourceHash
        self._sources    = { sourceHash: sourceToLoad }
        # Cache the current system capabilities to use for createActor
        # attempts.
        self.capabilities = currentSystemCapabilities
        self._actorClass = childClass  # nb. this may be a string, and sourceHash is not loaded yet
        self._childReqs  = childRequirements
        self.actorInst   = None
        thesplog('Starting Actor %s at %s (parent %s, admin %s)',
                 childClass, self.transport.myAddress,
                 self._parentAddr, adminAddr,
                 level = logging.INFO, primary=True)



    def _createInstance(self):
        aClass = self._actorClass
        try:
            aClass = actualActorClass(aClass,
                                      partial(loadModuleFromHashSource,
                                              self._sourceHash,
                                              self._sources)
                                      if self._sourceHash else None)
            # Now instantiate the identified Actor class object
            actorInst = aClass()
            self._sCBStats.inc('Actor.Instance Created')
        except Exception as ex:
            import traceback
            thesplog('Actor %s @ %s instantiation exception: %s', self._actorClass,
                     self.transport.myAddress, traceback.format_exc(),
                     level=logging.ERROR, primary=True)
            self._sCBStats.inc('Actor.Instance Create Failed')
            self._sayGoodbye()
            return

        self.actorInst = actorInst
        self.actorInst._myRef = self

<commit_msg>Add normal logging of actor instantiation failures as well as thesplog logging.<commit_after>"The ActorManager is the wrapper and support structure for an actual Actor instance."

import sys
import logging
import copy
from thespian.actors import *
from thespian.system.utilis import thesplog
from thespian.system.systemCommon import systemCommonBase
from thespian.system.addressManager import CannotPickleAddress
from thespian.system.transport import *
from thespian.system.messages.admin import *
from thespian.system.messages.status import Thespian_StatusReq, Thespian_ActorStatus
from thespian.system.messages import *
from thespian.system.messages.convention import NotifyOnSystemRegistration
from thespian.system.messages.logcontrol import SetLogging
from thespian.system.utilis import ExpiryTime, actualActorClass
from thespian.system.sourceLoader import loadModuleFromHashSource
from datetime import timedelta
from functools import partial


MAX_SHUTDOWN_DRAIN_PERIOD=timedelta(seconds=7)


class ActorManager(systemCommonBase):
    def __init__(self, childClass, transport, sourceHash, sourceToLoad,
                 parentAddr, adminAddr,
                 childRequirements, currentSystemCapabilities):
        super(ActorManager, self).__init__(adminAddr, transport)
        self._parentAddr = parentAddr
        self._sourceHash = sourceHash
        self._sources    = { sourceHash: sourceToLoad }
        # Cache the current system capabilities to use for createActor
        # attempts.
        self.capabilities = currentSystemCapabilities
        self._actorClass = childClass  # nb. this may be a string, and sourceHash is not loaded yet
        self._childReqs  = childRequirements
        self.actorInst   = None
        thesplog('Starting Actor %s at %s (parent %s, admin %s)',
                 childClass, self.transport.myAddress,
                 self._parentAddr, adminAddr,
                 level = logging.INFO, primary=True)



    def _createInstance(self):
        aClass = self._actorClass
        try:
            aClass = actualActorClass(aClass,
                                      partial(loadModuleFromHashSource,
                                              self._sourceHash,
                                              self._sources)
                                      if self._sourceHash else None)
            # Now instantiate the identified Actor class object
            actorInst = aClass()
            self._sCBStats.inc('Actor.Instance Created')
        except Exception as ex:
            import traceback
            logging.getLogger(str(self._actorClass)) \
                   .error('Actor %s @ %s instantiation exception',
                          self._actorClass, self.transport.myAddress,
                          exc_info = True)
            thesplog('Actor %s @ %s instantiation exception: %s', self._actorClass,
                     self.transport.myAddress, traceback.format_exc(),
                     level=logging.ERROR, primary=True)
            self._sCBStats.inc('Actor.Instance Create Failed')
            self._sayGoodbye()
            return

        self.actorInst = actorInst
        self.actorInst._myRef = self


{'fraction_non_alphanumeric': 0.061975998684859444, 'fraction_numerical': 0.0003287851389117212, 'mean_word_length': 2.4103139013452917, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3605723', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1459, 'n_words': 407}