One of the causes for the Ordovician mass extinction was an excess of gamma rays, predicted to be caused by a star going HYPERNOVA (from Wikipedia), 6,000 lightyears away, so the safe range is likely about 1000 for smaller hypernovas and for larger ones, up to 10,000 or 25,000. Again, this is a rough estimate, and it could be more or less. Wikipedia also states that in the first 30 seconds it stripped the Earth of half its ozone layer, ionized lots of nitrogen and oxygen which caused smog that is really bad for life.
Gamma ray bursts might not kill us with the radiation but they can cause a lot of harmful smog which is not good. But at that range, it only caused a mass extinction, about 85% of biodiversity, not 100%; the main issue with that 100% is that some life forms are extremely tough (not us humans; we are only tough because of our tools and weapons and guns won't help against a supernova).
Based on searching about supernovas, about 1% of all stars are 8 times the mass of the Sun. For a hypernova, we need something 4 times more massive than those. Since the Sun is actually a relatively large star (most stars are small read stars whose outer temperatures are about the same as our middle mantle with their mass being 0.2 to 0.38 solar masses, I'll go with 0.3 for now) 2 distributions away from those we have 8 solar masses, which means about 6 more distributions to get to 30, gives us that one in 108 stars can go hypernova. If a hypernova is dangerous within 5,000 lightyears, there will be a radius of the maximum of 1,000 stars assuming 5 lightyears of radius between stars on average; cube that and multiply it by 4/3 × π, we get about 4 billion stars, where 40 of them can go supernova. However, most of these super nova aren't ready yet, and most are yet to be born though some nebulae like the tarantulas nebula have lots of stars with up to 200-300 solar masses, which can make a blast, those are real far from us, and in the range of stars that can harm us, we get about one problematic hypernova every 250 million years (10 billion divided by 40). This coincides with the dangerous supernova that I read about while searching.