Write and close sessions before executing jobs to avoid blocking and undesireable behavior