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

Commit

Permalink
Add shutdowns (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
Belbs authored Jul 6, 2017
1 parent 137b9e0 commit eec43da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
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

0 comments on commit eec43da

Please sign in to comment.