<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def task_add(self, t, periodic=None):
 """ Register a task in this legion. "periodic" should be None, or a callback function which will be called periodically when the legion is otherwise idle. """

        name = t.get_name()
        if name in self._tasknames:
            raise TaskError(name, 'Task already exists with %d daemon%s active' %
                            (len(self._tasknames), ses(len(self._tasknames))))
        self._tasknames[name] = (t, periodic)
        self._tasks.add(t)