Changed @in_task to be correctly modified if an exception is raised while executing a task