Hours away from a midnight deadline, Canadian Pacific Railway Ltd. is trying to hammer out a deal with two unions to avoid a labor strike that threatens to disrupt Canada’s second largest railroad for the second time in three years.

Talks are continuing in Calgary between the railway, the International Brotherhood of Electrical Workers and Teamsters Canada, Jeremy Berry, a Canadian Pacific spokesman, said Friday via e-mail. The unions, which represent more than 3,000 train conductors, engineers and electrical workers, have said their members would walk off the job as early as 12:01 a.m. Saturday if no agreement is reached.

A work stoppage would hamstring Canadian Pacific’s ability to provide freight service in a country already buffeted by congestion on a rival railroad’s network. Commuters in Toronto, Canada’s largest city, would also suffer because some of the trains they ride use Canadian Pacific’s tracks.