Skip to content

Commit c5fc5a4

Browse files
PEP 788: Minor editorial fixes (#4477)
* Clarify that weak references cannot be promoted postmortem. * Get rid of 'plethora'. * Clarify that PyInterpreterWeakRef_AsStrong() does not set an exception. * Add some clarity to 'A Library Interface' * Clarify that PyInterpreterWeakRef will always be pointer-sized. * Add quote links to 'Daemon Threads Are Not the Problem'
1 parent 18f4d04 commit c5fc5a4

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

peps/pep-0788.rst

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ Prior to this PEP, deprecating daemon threads was discussed
181181
`extensively <https://discuss.python.org/t/68836>`_. Daemon threads technically
182182
cause many of the issues outlined in this proposal, so removing daemon threads
183183
could be seen as a potential solution. The main argument for removing daemon
184-
threads is that they're a large cause of problems in the interpreter:
184+
threads is that they're a large cause of problems in the interpreter
185+
`[1] <https://discuss.python.org/t/68836/6>`_.
185186

186187
Except that daemon threads don’t actually work reliably. They’re attempting
187188
to run and use Python interpreter resources after the runtime has been shut
@@ -190,7 +191,8 @@ threads is that they're a large cause of problems in the interpreter:
190191

191192
However, in practice, daemon threads are useful for simplifying many threading
192193
applications in Python, and since the program is about to close in most cases,
193-
it's not worth the added complexity to try and gracefully shut down a thread.
194+
it's not worth the added complexity to try and gracefully shut down a thread
195+
`[2] <https://discuss.python.org/t/68836/3>`_.
194196

195197
When I’ve needed daemon threads, it’s usually been the case of “Long-running,
196198
uninterruptible, third-party task” in terms of the examples in the linked issue.
@@ -205,7 +207,8 @@ As noted by this PEP, extension modules are free to create their own threads
205207
and attach thread states for them. Similar to daemon threads, Python doesn't
206208
try and join them during finalization, so trying to remove daemon threads
207209
as a whole would involve trying to remove them from the C API, which would
208-
require a much more massive API change.
210+
require a much more massive API change than what is currently being proposed
211+
`[3] <https://discuss.python.org/t/68836/7>`_.
209212

210213
Realize however that even if we get rid of daemon threads, extension
211214
module code can and does spawn its own threads that are not tracked by
@@ -379,20 +382,23 @@ Weak References
379382

380383
This proposal also comes with weak references to an interpreter that don't
381384
prevent it from shutting down, but can be promoted to a strong reference when
382-
the user decides that they want to call the C API. A weak reference will
383-
typically live much longer than a strong reference. This is useful for many of
384-
the asynchronous situations stated previously, where the thread itself
385-
shouldn't prevent the desired interpreter from shutting down, but also allow
386-
the thread to execute Python when needed.
385+
the user decides that they want to call the C API. If an interpreter is
386+
destroyed or past the point where it can create strong references, promotion
387+
of a weak reference will fail.
388+
389+
A weak reference will typically live much longer than a strong reference.
390+
This is useful for many of the asynchronous situations stated previously,
391+
where the thread itself shouldn't prevent the desired interpreter from shutting
392+
down, but also allow the thread to execute Python when needed.
387393

388394
For example, a (non-reentrant) event handler may store a weak interpreter
389395
reference in its ``void *arg`` parameter, and then that weak reference will
390396
be promoted to a strong reference when it's time to call Python code.
391397

392-
Deprecation of the GIL-state APIs
393-
---------------------------------
398+
Removing the outdated GIL-state APIs
399+
------------------------------------
394400

395-
Due to the plethora of issues with ``PyGILState``, this PEP intends to do away
401+
Due to the unfixable issues with ``PyGILState``, this PEP intends to do away
396402
with them entirely. In today's C API, all ``PyGILState`` functions are
397403
replaceable with ``PyThreadState`` counterparts that are compatibile with
398404
subinterpreters:
@@ -507,6 +513,8 @@ Weak Interpreter References
507513
The interpreter will *not* wait for the reference to be
508514
released before shutting down.
509515
516+
This type is guaranteed to be pointer-sized.
517+
510518
.. c:function:: int PyInterpreterWeakRef_Get(PyInterpreterWeakRef *wref)
511519
512520
Acquire a weak reference to the current interpreter.
@@ -535,7 +543,8 @@ Weak Interpreter References
535543
reference to the interpreter denoted by *wref*.
536544
537545
If the interpreter no longer exists or has already finished waiting
538-
for its reference count to reach zero, then this function returns ``-1``.
546+
for its reference count to reach zero, then this function returns ``-1``
547+
without an exception set.
539548
540549
This function is not safe to call in a re-entrant signal handler.
541550
@@ -679,8 +688,8 @@ If you were to use :c:func:`PyGILState_Ensure` for this case, then your
679688
thread would hang if the interpreter were to be finalizing at that time!
680689
681690
Additionally, the API supports subinterpreters. If you were to assume that
682-
the main interpreter created the file object, then your library wouldn't be safe to use
683-
with file objects created by a subinterpreter.
691+
the main interpreter created the file object (via :c:func:`PyGILState_Ensure`),
692+
then using file objects owned by a subinterpreter could possibly crash.
684693
685694
Example: A Single-threaded Ensure
686695
*********************************

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy