It depends on your location.
In general, in the U.S. it's always ok to pull your gun if deadly force is legally justified. In some areas you may be able to pull it sooner, but it's always safe to pull it if deadly force is already legally justified.
So when is deadly force legally justified? In the U.S. it's pretty safe (legally speaking) to use deadly force if:
1. You are not currently in the process of committing a serious crime.
2. You did not instigate the confrontation/situation.
3. You have no other reasonable alternative but to use deadly force.
4. The person who will be the focus of deadly force is currently committing or immediately about to commit a violent felony against you.
5. You reasonably believe that if you do not immediately use deadly force you will be seriously injured or killed.
In some areas you may be able to legally use deadly force in other situations, but it's a good bet that you can legally use deadly force under the circumstances described above.