Hi Kevin,
I have another one for you:
from thespian.troupe import troupe
from thespian.actors import ActorTypeDispatcher, Actor
from thespian.actors import ActorSystem
import logging
import time
def logfile_extraction(log_files):
"""
Gets data from logfile and returns as string
:param log_files: string, path to logfile
:return: string
"""
consolidated_output = ""
for logfile in log_files:
with open(logfile, "r+") as file:
consolidated_output += file.read()
return consolidated_output
class ActorLogFilter(logging.Filter):
def filter(self, logrecord):
return 'actorAddress' in logrecord.__dict__
class NotActorLogFilter(logging.Filter):
def filter(self, logrecord):
return 'actorAddress' not in logrecord.__dict__
def log_config(log_file_path_1, log_file_path_2):
return {
'version': 1,
'formatters': {
'normal': {'format': '%(levelname)-8s %(message)s'},
'actor': {'format': '%(levelname)-8s %(actorAddress)s => %(message)s'}},
'filters': {'isActorLog': {'()': ActorLogFilter},
'notActorLog': {'()': NotActorLogFilter}},
'handlers': {'h1': {'class': 'logging.FileHandler',
'filename': log_file_path_1,
'formatter': 'normal',
'filters': ['notActorLog'],
'level': logging.INFO},
'h2': {'class': 'logging.FileHandler',
'filename': log_file_path_2,
'formatter': 'actor',
'filters': ['isActorLog'],
'level': logging.INFO}, },
'loggers': {'': {'handlers': ['h1', 'h2'], 'level': logging.DEBUG}}
}
class PrimaryActor(Actor):
def receiveMessage(self, msg, sender):
test_data = [
[1, 2, 3, 4, 5] * 2,
[6, 7, 8, 9, 10] * 2,
[11, 12, 13, 14, 15] * 2,
[16, 17, 18, 19, 20] * 2,
[21, 22, 23, 24, 25] * 2,
[1, 2, 3, 4, 5] * 2,
[6, 7, 8, 9, 10] * 2,
[11, 12, 13, 14, 15] * 2,
[16, 17, 18, 19, 20] * 2,
[21, 22, 23, 24, 25] * 2,
[1, 2, 3, 4, 5] * 2
]
if not hasattr(self, "helper"):
self.helper = self.createActor(
SecondaryActor
)
for data in test_data:
self.send(
self.helper,
data
)
@troupe(max_count=200, idle_count=1)
class SecondaryActor(ActorTypeDispatcher):
received_message_count = 0
def receiveMessage(self, msg, sender):
if isinstance(msg, list):
if not hasattr(self, "helper"):
self.helper = self.createActor(
TertiaryActor
)
for data in msg:
self.send(
self.helper,
data
)
@troupe(max_count=200, idle_count=1)
class TertiaryActor(ActorTypeDispatcher):
received_message_count = 0
def receiveMessage(self, msg, sender):
qa = self.createActor(
QuaternaryActor,
globalName="quaternay"
)
self.send(
qa,
msg
)
@troupe(max_count=200, idle_count=1)
class QuaternaryActor(ActorTypeDispatcher):
def receiveMessage(self, msg, sender):
if isinstance(msg, int):
logging.info("Received message number {0}".format(msg))
thespian_system = ActorSystem(
"multiprocTCPBase",
{},
logDefs=log_config("bug_check_1.log", "bug_check_2.log")
)
primary_actor = thespian_system.createActor(PrimaryActor)
quaternary_actor = thespian_system.createActor(
QuaternaryActor,
globalName="quaternay"
)
thespian_system.tell(primary_actor, {})
I am expecting to see 110 'Received message' entries in logfile. Instead the actor system hangs, actors stop work but are still there. My logfile output (truncated) is:
INFO ActorAddr-(T|:39395) => Received message number 1
INFO ActorAddr-(T|:39395) => Received message number 6
INFO ActorAddr-(T|:41401) => Received message number 2
INFO ActorAddr-(T|:40165) => Received message number 9
INFO ActorAddr-(T|:45173) => Received message number 3
INFO ActorAddr-(T|:36873) => Received message number 7
INFO ActorAddr-(T|:45585) => Received message number 21
INFO ActorAddr-(T|:34161) => Received message number 4
INFO ActorAddr-(T|:40759) => Received message number 13
INFO ActorAddr-(T|:46429) => Received message number 8
INFO ActorAddr-(T|:42633) => Received message number 12
INFO ActorAddr-(T|:44969) => Received message number 5
INFO ActorAddr-(T|:42815) => Received message number 10
INFO ActorAddr-(T|:42815) => Received message number 4
INFO ActorAddr-(T|:34829) => Received message number 14
INFO ActorAddr-(T|:34829) => Received message number 9
INFO ActorAddr-(T|:38961) => Received message number 10
INFO ActorAddr-(T|:41837) => Received message number 24
INFO ActorAddr-(T|:41837) => Received message number 4
INFO ActorAddr-(T|:41837) => Received message number 25
INFO ActorAddr-(T|:41837) => Received message number 5
INFO ActorAddr-(T|:41837) => Received message number 5
INFO ActorAddr-(T|:41837) => Received message number 10
INFO ActorAddr-(T|:41837) => Received message number 14
INFO ActorAddr-(T|:41837) => Received message number 15
INFO ActorAddr-(T|:41837) => Received message number 24
INFO ActorAddr-(T|:41837) => Received message number 25
INFO ActorAddr-(T|:38785) => Received message number 15
INFO ActorAddr-(T|:33405) => Received message number 9
ERROR ActorAddr-(T|:46227) => Pending Actor create for ActorAddr-(T|:46227) failed (3585): None
ERROR ActorAddr-(T|:40795) => Pending Actor create for ActorAddr-(T|:40795) failed (3585): None
ERROR ActorAddr-(T|:42263) => Pending Actor create for ActorAddr-(T|:42263) failed (3585): None
ERROR ActorAddr-(T|:46227) => Pending Actor create for ActorAddr-(T|:46227) failed (3585): None
ERROR ActorAddr-(T|:35911) => Pending Actor create for ActorAddr-(T|:35911) failed (3585): None
ERROR ActorAddr-(T|:45909) => Pending Actor create for ActorAddr-(T|:45909) failed (3585): None
ERROR ActorAddr-(T|:35911) => Pending Actor create for ActorAddr-(T|:35911) failed (3585): None
ERROR ActorAddr-(T|:35911) => Pending Actor create for ActorAddr-(T|:35911) failed (3585): None
ERROR ActorAddr-(T|:46227) => Pending Actor create for ActorAddr-(T|:46227) failed (3585): None
ERROR ActorAddr-(T|:44393) => Pending Actor create for ActorAddr-(T|:44393) failed (3585): None
ERROR ActorAddr-(T|:45909) => Pending Actor create for ActorAddr-(T|:45909) failed (3585): None
ERROR ActorAddr-(T|:38583) => Pending Actor create for ActorAddr-(T|:38583) failed (3585): None
ERROR ActorAddr-(T|:46227) => Pending Actor create for ActorAddr-(T|:46227) failed (3585): None
ERROR ActorAddr-(T|:44393) => Pending Actor create for ActorAddr-(T|:44393) failed (3585): None
ERROR ActorAddr-(T|:45909) => Pending Actor create for ActorAddr-(T|:45909) failed (3585): None
ERROR ActorAddr-(T|:35119) => Pending Actor create for ActorAddr-(T|:35119) failed (3585): None
ERROR ActorAddr-(T|:38583) => Pending Actor create for ActorAddr-(T|:38583) failed (3585): None
ERROR ActorAddr-(T|:45909) => Pending Actor create for ActorAddr-(T|:45909) failed (3585): None
ERROR ActorAddr-(T|:44535) => Pending Actor create for ActorAddr-(T|:44535) failed (3585): None
ERROR ActorAddr-(T|:45909) => Pending Actor create for ActorAddr-(T|:45909) failed (3585): None
ERROR ActorAddr-(T|:35119) => Pending Actor create for ActorAddr-(T|:35119) failed (3585): None
ERROR ActorAddr-(T|:44393) => Pending Actor create for ActorAddr-(T|:44393) failed (3585): None
ERROR ActorAddr-(T|:38583) => Pending Actor create for ActorAddr-(T|:38583) failed (3585): None
ERROR ActorAddr-(T|:44535) => Pending Actor create for ActorAddr-(T|:44535) failed (3585): None
ERROR ActorAddr-(T|:44393) => Pending Actor create for ActorAddr-(T|:44393) failed (3585): None
ERROR ActorAddr-(T|:38583) => Pending Actor create for ActorAddr-(T|:38583) failed (3585): None
ERROR ActorAddr-(T|:35119) => Pending Actor create for ActorAddr-(T|:35119) failed (3585): None
ERROR ActorAddr-(T|:46227) => Pending Actor create for ActorAddr-(T|:46227) failed (3585): None
ERROR ActorAddr-(T|:35119) => Pending Actor create for ActorAddr-(T|:35119) failed (3585): None
ERROR ActorAddr-(T|:44535) => Pending Actor create for ActorAddr-(T|:44535) failed (3585): None
ERROR ActorAddr-(T|:44393) => Pending Actor create for ActorAddr-(T|:44393) failed (3585): None
ERROR ActorAddr-(T|:44535) => Pending Actor create for ActorAddr-(T|:44535) failed (3585): None
ERROR ActorAddr-(T|:38503) => Pending Actor create for ActorAddr-(T|:38503) failed (3585): None
ERROR ActorAddr-(T|:38503) => Pending Actor create for ActorAddr-(T|:38503) failed (3585): None
ERROR ActorAddr-(T|:35245) => Pending Actor create for ActorAddr-(T|:35245) failed (3585): None
ERROR ActorAddr-(T|:37605) => Pending Actor create for ActorAddr-(T|:37605) failed (3585): None
ERROR ActorAddr-(T|:38503) => Pending Actor create for ActorAddr-(T|:38503) failed (3585): None
ERROR ActorAddr-(T|:35245) => Pending Actor create for ActorAddr-(T|:35245) failed (3585): None
ERROR ActorAddr-(T|:37605) => Pending Actor create for ActorAddr-(T|:37605) failed (3585): None
ERROR ActorAddr-(T|:34611) => Pending Actor create for ActorAddr-(T|:34611) failed (3585): None
ERROR ActorAddr-(T|:37605) => Pending Actor create for ActorAddr-(T|:37605) failed (3585): None
ERROR ActorAddr-(T|:34611) => Pending Actor create for ActorAddr-(T|:34611) failed (3585): None
/tmp/thespian.log is:
2019-03-28 20:31:44.250386 p10786 ERR Socket error sending to ActorAddr-(T|:44599) on <socket.socket fd=29, family=AddressFamily.AF_INET, type=2049, proto=6, laddr=('192.168.0.14', 35535)>: [Errno 104] Connection reset by peer / 104: ************* TransportIntent(ActorAddr-(T|:44599)-pending-ExpiresIn_0:04:59.999222-<class 'thespian.actors.ChildActorExited'>-ChildActorExited:ActorAddr-(T|:35535)-quit_0:04:59.999193)
2019-03-28 20:31:53.808630 p10385 ERR No response to Admin shutdown request; Actor system not completely shutdown
Any ideas what'ts going on?
Thanks