diff --git a/awx/main/tasks.py b/awx/main/tasks.py index 3aeaadd786..0de7094100 100644 --- a/awx/main/tasks.py +++ b/awx/main/tasks.py @@ -993,9 +993,10 @@ class BaseTask(LogErrorsTask): logger.exception('%s Exception occurred while running task', instance.log_format) finally: try: - stdout_handle.flush() - stdout_handle.close() - event_ct = getattr(stdout_handle, '_event_ct', 0) + if stdout_handle: + stdout_handle.flush() + stdout_handle.close() + event_ct = getattr(stdout_handle, '_event_ct', 0) logger.info('%s finished running, producing %s events.', instance.log_format, event_ct) except Exception: