I believe the traffic signals are controlled through the track circuits so they will work for freights as well. Also, if you look closely, at all three intersections on one of the poles there is a pair of flashing white lights, to indicate to the engineer that the signals are lined for him.
Also like motorists, engineers try to time the signals, but occasionally a train will have to stop and wait for a green light, thus activating the lineup for the train. The lights don't automatically turn green every time a train approaches.