Notwithstanding any city or county or city and county ordinance to the contrary, no railroad conductor or engineer, who, while operating a train, obstructs a railroad crossing, shall be subject to any criminal penalty, where he has no control over the situation causing the obstruction, or where the train cannot be moved without endangering the safety of the passengers or freight.