convert set_current_task to context manager