PEP 788: Protecting the C API from Interpreter Finalization

Yeah, I think PyInterpreterView is a fine name too. My worry with “block finalization” as a verb is that it’s going to be long and cumbersome to type (e.g., PyFinalizationGuard_BlockFinalizationFromCurrent). Would it be okay to use something like PyFinalizationGuard_FromCurrent instead?

Regarding PyFinalizationGuard vs PyInterpreterGuard, I slightly like the latter more in case we ever want to use guards to block other things in the interpreter as well, but I won’t care too much if we ultimately choose PyFinalizationGuard

Why not PyBlockFinalization_FromCurrent()? It would fit with Py_Finalize() name, no?

Or maybe just PyBlockFinalize_FromCurrent().

“block finalization” is a verb, and I’m not aware of any C APIs with a verb as the prefix. I like Alyssa’s suggestion of “finalization guard” more.

No, it’s a noun. “Finalize” is a verb, “finalization” is a noun derived
from it.

“finalization” is a noun, yes, but “block finalization” functions as a verb.

No, it doesn’t. Write down a sentence with a verb in it, replace the verb with “block finalization”, and see whether it still sounds grammatical.

Obligatory: I can sentence how I want (source)

2 Likes

For example, as an infinitive phrase:

  1. “To block finalization is the core developer’s goal.”
  2. “To write code is the core developer’s goal.”

I agree with @h-vetinari that English is weird, and I don’t think this discussion is productive. If you want to argue that only “block” is the verb and “finalization” is the object, fine, but our C API usually doesn’t contain any verbs in the prefix, nonetheless. (For example, we use PyList_Append, not PyAppend_List.)

2 Likes

It’s possible I misunderstood. I was reading “block” as a noun, as in a block of code. If it’s meant as a verb in this context, as in to stop something from happening, the corresponding noun phrase would be “finalization blocking”.

I hadn’t considered the noun meaning of “block”, so the unambiguous “Prevent” may be better.

With that switched, I was suggesting top level APIs like Py_PreventFinalization (current interpreter only), PyInterpreterView_PreventFinalization (accepts a view), and Py_AllowFinalization, omitting the FinalizationGuard part of the prefix for the “current interpreter” variants, since the verb phrases aren’t generic ones that need to be scoped to a particular kind of struct.

I read Py_PreventFinalization as blocking runtime finalization (i.e., Py_Finalize) rather than interpreter finalization (i.e., Py_EndInterpreter), because we usually reserve the Py_ prefix for high-level runtime operations. I think we want some sort of prefix to disambiguate that.

2 Likes

What’s wrong with PyInterpreterGuard? I haven’t seen any argument against it.

1 Like

I think that’s the cleanest option too.

What do you think of PyFinalizationGuard or PyFinalizeGuard?

1 Like

Well, I agree with this argument:

1 Like

Hmm, fair. So using the guard option would be:

  • PyInterpreterGuard_FromCurrent
  • PyInterpreterGuard_FromView
  • PyInterpreterGuard_Release

And we’d use phrasing like “guarding against interpreter shutdown” in the documentation.

I was hesitant to add the new noun without a more explicit qualifier than “interpreter” (since there’s nothing about “guard” that specifically indicates “prevents shutdown”), but maybe “not a lock and not a counted reference” is sufficient “at a glance” info, with the docs filling in the rest.

1 Like

Me too, and that’s why I wrote prior revisions that tried to fit with existing systems, but ultimately there’s no established term that applies here.

And trying to get the full phrase “interpreter finalization guard” directly into the name is definitely too verbose.

Since I agree that shortening it to “finalization guard” would be ambiguous about whether it’s a runtime or per-interpreter API, that leaves me also agreeing that “interpreter guard” is the best option out of the various names we’ve considered.

2 Likes

The PEP has been updated to use PyInterpreterGuard.

4 Likes

The C API WG has approved the PEP. I’ve submitted PEP 788 to the Steering Council: PEP 788 -- Protecting the C API from Interpreter Finalization · Issue #316 · python/steering-council · GitHub

Thanks everyone for the discussion!

5 Likes