<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _run_events(self, shutdown=False):
 """ Runs event hooks for registered event plugins. `shutdown` Set to ``True`` to run task_end events; otherwise, run task_run events. """


        # run task_start events, if not ran already
        if not self._ran_taskstart:
            self._ran_taskstart = True
            registration.run_event_hooks('task_start', self._task)

        # run events
        event = 'task_end' if shutdown else 'task_run'
        registration.run_event_hooks(event, self._task)

        # reclaim any subprocesses plugins may have forked
        try:
            os.waitpid(-1, os.P_NOWAIT)
        except OSError:
            pass