Harvey Weinstein’s rape trial took a dramatic turn on Tuesday as the judge threatened to revoke his bail and jail the former film producer after catching him using his cellphone just as jury selection got underway.

“Is this really the way you want to end up in jail for the rest of your life, by texting and violating a court order?” state Judge James Burke asked, visibly angry. He told Weinstein not to answer.

Assistant District Attorney Joan Illuzzi, the lead prosecutor, urged Burke to jail Weinstein.

“There is a grave risk that this defendant at some point will realize that the evidence against him is imposing and overwhelming” and he will try to flee, she said.

The judge ultimately decided not to jail Weinstein but warned he would not get another chance.

“I’m not looking for apologies; I’m looking for compliance,” Burke said.

Weinstein has been released on bail, but is required to wear an electronic-tracking device that was visible on his ankle as he got out of a sports utility vehicle when he arrived at court on Tuesday.