Beispiel #1
0
    def remove_team(self, sessionteam: ba.SessionTeam) -> None:
        """(internal)"""

        # This should only be called on unexpired activities the team has
        # been added to.
        assert not self.expired
        assert sessionteam.gameteam is not None
        assert sessionteam.gameteam in self.teams

        team = sessionteam.gameteam
        assert isinstance(team, self._teamtype)

        assert team in self.teams
        self.teams.remove(team)
        assert team not in self.teams

        with _ba.Context(self):
            # Make a decent attempt to persevere if user code breaks.
            try:
                self.on_team_leave(team)
            except Exception:
                print_exception(f'Error in on_team_leave for {self}')
            try:
                sessionteam.reset_gamedata()
            except Exception:
                print_exception(f'Error in reset_gamedata for {self}')
            sessionteam.gameteam = None
Beispiel #2
0
    def remove_team(self, sessionteam: ba.SessionTeam) -> None:
        """Remove a team from a Running Activity

        (internal)
        """
        assert not self.expired
        assert sessionteam.gameteam is not None

        team: Any = sessionteam.gameteam
        assert isinstance(team, self._teamtype)

        assert team in self.teams
        self.teams.remove(team)
        assert team not in self.teams

        with _ba.Context(self):
            # Make a decent attempt to persevere if user code breaks.
            try:
                self.on_team_leave(team)
            except Exception:
                print_exception(f'Error in on_team_leave for {self}')
            try:
                team.leave()
            except Exception:
                print_exception(f'Error on leave for {team} in {self}')

            sessionteam.gameteam = None

        # Add the team to a list to keep it around for a while. This is
        # to discourage logic from firing on team object death, which
        # may not happen until activity end if something is holding refs
        # to it.
        self._delay_delete_teams.append(team)
        self._teams_that_left.append(weakref.ref(team))