@@ -181,7 +181,8 @@ Prior to this PEP, deprecating daemon threads was discussed
181
181
`extensively <https://discuss.python.org/t/68836 >`_. Daemon threads technically
182
182
cause many of the issues outlined in this proposal, so removing daemon threads
183
183
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 >`_.
185
186
186
187
Except that daemon threads don’t actually work reliably. They’re attempting
187
188
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:
190
191
191
192
However, in practice, daemon threads are useful for simplifying many threading
192
193
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 >`_.
194
196
195
197
When I’ve needed daemon threads, it’s usually been the case of “Long-running,
196
198
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
205
207
and attach thread states for them. Similar to daemon threads, Python doesn't
206
208
try and join them during finalization, so trying to remove daemon threads
207
209
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 >`_.
209
212
210
213
Realize however that even if we get rid of daemon threads, extension
211
214
module code can and does spawn its own threads that are not tracked by
@@ -379,20 +382,23 @@ Weak References
379
382
380
383
This proposal also comes with weak references to an interpreter that don't
381
384
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.
387
393
388
394
For example, a (non-reentrant) event handler may store a weak interpreter
389
395
reference in its ``void *arg `` parameter, and then that weak reference will
390
396
be promoted to a strong reference when it's time to call Python code.
391
397
392
- Deprecation of the GIL-state APIs
393
- ---------------------------------
398
+ Removing the outdated GIL-state APIs
399
+ ------------------------------------
394
400
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
396
402
with them entirely. In today's C API, all ``PyGILState `` functions are
397
403
replaceable with ``PyThreadState `` counterparts that are compatibile with
398
404
subinterpreters:
@@ -507,6 +513,8 @@ Weak Interpreter References
507
513
The interpreter will *not* wait for the reference to be
508
514
released before shutting down.
509
515
516
+ This type is guaranteed to be pointer-sized.
517
+
510
518
.. c:function:: int PyInterpreterWeakRef_Get(PyInterpreterWeakRef *wref)
511
519
512
520
Acquire a weak reference to the current interpreter.
@@ -535,7 +543,8 @@ Weak Interpreter References
535
543
reference to the interpreter denoted by *wref *.
536
544
537
545
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.
539
548
540
549
This function is not safe to call in a re-entrant signal handler.
541
550
@@ -679,8 +688,8 @@ If you were to use :c:func:`PyGILState_Ensure` for this case, then your
679
688
thread would hang if the interpreter were to be finalizing at that time!
680
689
681
690
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 .
684
693
685
694
Example: A Single-threaded Ensure
686
695
*********************************
0 commit comments