Ad 1.:
Threads interact strangely with interrupts: the KeyboardInterrupt
exception will be received by an arbitrary thread. (When the signal
module is available, interrupts always go to the main thread.)
I have no idea what you mean by testing this one.
On my system (with signal
accessible), SIGINT is (quite obviously) handled in the main thread. It does not answer, however, whether the above statement is true/up-to-date.
Ad 2.:
When the main thread exits, it does not do any of its usual cleanup (except that try
… finally
clauses are honored), and the standard I/O files are not flushed.
I’ve done a quick test (see below) which shows that, as i surmised, this statement is not true when it comes to my (Linux) system. But, of course, the test cannot prove that the statement is not true for every platform and that it should be removed from the docs.
The only sure thing about the above statement is that, at least for me, it is unclear: is the cleanup/flushing limitation supposed to apply always on platforms with threads, or only if a thread has been spawned?
I suppose that a core developer familiar with this part of the implementation could easily tell whether each of the two cited statements is true/up-to-date at all (universally, not just for my platform) – that’s why I ask these questions here.
As I stressed, I’d be happy to create a PR with a docs fix – but it seems it does not make sense to create one until somebody more competent than me confirms that a fix is needed indeed.
<my shell prompt>$ python3.11
Python 3.11.8 (main, Apr 10 2024, 21:47:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import atexit, sys, _thread
>>> f = open('spam', 'xb')
>>> atexit.register(f.write, b'1')
<built-in method write of _io.BufferedWriter object at 0x7fecc8ed8e00>
>>> _ = _thread.start_new_thread(sys.__stdout__.write, ('foo',))
>>> sys.exit()
foo<my shell prompt>$ cat spam
1
<my shell prompt>$ python3.14 -W ignore
Python 3.14.0a0 (heads/main:e83ce850f4, Jun 5 2024, 20:35:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import atexit, sys, _thread
>>> f = open('spam42', 'xb')
>>> atexit.register(f.write, b'42')
<built-in method write of _io.BufferedWriter object at 0x7fe6764816d0>
>>> _ = _thread.start_new_thread(sys.__stderr__.write, ('foo',))
>>> sys.exit()
foo<my shell prompt>$ cat spam42
42