Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Add shutdowns #191

Merged
merged 2 commits into from
Jul 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions parlai/core/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def shutdown(self):
"""Perform any final cleanup if needed."""
pass


class Teacher(Agent):
"""Basic Teacher agent which keeps track of how many times it's received
messages. Teachers provide the ``report()`` method to get back metrics."""
Expand Down Expand Up @@ -150,6 +151,7 @@ def share(self):
shared['metrics'] = self.metrics
return shared


class MultiTaskTeacher(Teacher):
"""Creates a teacher that is actually a set of teachers each based on
a task string--each of these teachers will get called in turn,
Expand Down Expand Up @@ -259,6 +261,12 @@ def share(self):
shared['tasks'] = [t.share() for t in self.tasks]
return shared

def shutdown(self):
"""Shutdown each agent."""
for t in self.tasks:
t.shutdown()


def name_to_agent_class(name):
words = name.split('_')
class_name = ''
Expand Down
7 changes: 7 additions & 0 deletions parlai/core/worlds.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def report(self):
return self.agents[0].report()

def shutdown(self):
"""Shutdown each agent."""
for a in self.agents:
a.shutdown()

Expand Down Expand Up @@ -632,6 +633,12 @@ def reset(self):
def reset_metrics(self):
self.worlds[0].reset_metrics()

def shutdown(self):
"""Shutdown each world."""
for w in self.worlds:
w.shutdown()
self.world.shutdown()


class HogwildProcess(Process):
"""Process child used for ``HogwildWorld``.
Expand Down