Add drain method that removes the task's events and unlocks the task to run again.
Switch to task.drain() method. Add debug outpu. Replace missing 'socket' import.