Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d714bfe

Browse files
committed
Deploying to gh-pages from @ c3d3dee 🚀
1 parent 1503bee commit d714bfe

File tree

555 files changed

+4958
-4613
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

555 files changed

+4958
-4613
lines changed

_sources/library/subprocess.rst.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,6 +1591,24 @@ handling consistency are valid for these functions.
15911591
Notes
15921592
-----
15931593

1594+
.. _subprocess-timeout-behavior:
1595+
1596+
Timeout Behavior
1597+
^^^^^^^^^^^^^^^^
1598+
1599+
When using the ``timeout`` parameter in functions like :func:`run`,
1600+
:meth:`Popen.wait`, or :meth:`Popen.communicate`,
1601+
users should be aware of the following behaviors:
1602+
1603+
1. **Process Creation Delay**: The initial process creation itself cannot be interrupted
1604+
on many platform APIs. This means that even when specifying a timeout, you are not
1605+
guaranteed to see a timeout exception until at least after however long process
1606+
creation takes.
1607+
1608+
2. **Extremely Small Timeout Values**: Setting very small timeout values (such as a few
1609+
milliseconds) may result in almost immediate :exc:`TimeoutExpired` exceptions because
1610+
process creation and system scheduling inherently require time.
1611+
15941612
.. _converting-argument-sequence:
15951613

15961614
Converting an argument sequence to a string on Windows

_sources/library/threading.rst.txt

Lines changed: 118 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,132 @@ All of the methods described below are executed atomically.
260260
Thread-Local Data
261261
-----------------
262262

263-
Thread-local data is data whose values are thread specific. To manage
264-
thread-local data, just create an instance of :class:`local` (or a
265-
subclass) and store attributes on it::
263+
Thread-local data is data whose values are thread specific. If you
264+
have data that you want to be local to a thread, create a
265+
:class:`local` object and use its attributes::
266266

267-
mydata = threading.local()
268-
mydata.x = 1
267+
>>> mydata = local()
268+
>>> mydata.number = 42
269+
>>> mydata.number
270+
42
269271

270-
The instance's values will be different for separate threads.
272+
You can also access the :class:`local`-object's dictionary::
273+
274+
>>> mydata.__dict__
275+
{'number': 42}
276+
>>> mydata.__dict__.setdefault('widgets', [])
277+
[]
278+
>>> mydata.widgets
279+
[]
280+
281+
If we access the data in a different thread::
282+
283+
>>> log = []
284+
>>> def f():
285+
... items = sorted(mydata.__dict__.items())
286+
... log.append(items)
287+
... mydata.number = 11
288+
... log.append(mydata.number)
289+
290+
>>> import threading
291+
>>> thread = threading.Thread(target=f)
292+
>>> thread.start()
293+
>>> thread.join()
294+
>>> log
295+
[[], 11]
296+
297+
we get different data. Furthermore, changes made in the other thread
298+
don't affect data seen in this thread::
299+
300+
>>> mydata.number
301+
42
302+
303+
Of course, values you get from a :class:`local` object, including their
304+
:attr:`~object.__dict__` attribute, are for whatever thread was current
305+
at the time the attribute was read. For that reason, you generally
306+
don't want to save these values across threads, as they apply only to
307+
the thread they came from.
308+
309+
You can create custom :class:`local` objects by subclassing the
310+
:class:`local` class::
311+
312+
>>> class MyLocal(local):
313+
... number = 2
314+
... def __init__(self, /, **kw):
315+
... self.__dict__.update(kw)
316+
... def squared(self):
317+
... return self.number ** 2
318+
319+
This can be useful to support default values, methods and
320+
initialization. Note that if you define an :py:meth:`~object.__init__`
321+
method, it will be called each time the :class:`local` object is used
322+
in a separate thread. This is necessary to initialize each thread's
323+
dictionary.
324+
325+
Now if we create a :class:`local` object::
326+
327+
>>> mydata = MyLocal(color='red')
328+
329+
we have a default number::
330+
331+
>>> mydata.number
332+
2
333+
334+
an initial color::
335+
336+
>>> mydata.color
337+
'red'
338+
>>> del mydata.color
339+
340+
And a method that operates on the data::
341+
342+
>>> mydata.squared()
343+
4
344+
345+
As before, we can access the data in a separate thread::
346+
347+
>>> log = []
348+
>>> thread = threading.Thread(target=f)
349+
>>> thread.start()
350+
>>> thread.join()
351+
>>> log
352+
[[('color', 'red')], 11]
353+
354+
without affecting this thread's data::
355+
356+
>>> mydata.number
357+
2
358+
>>> mydata.color
359+
Traceback (most recent call last):
360+
...
361+
AttributeError: 'MyLocal' object has no attribute 'color'
362+
363+
Note that subclasses can define :term:`__slots__`, but they are not
364+
thread local. They are shared across threads::
365+
366+
>>> class MyLocal(local):
367+
... __slots__ = 'number'
368+
369+
>>> mydata = MyLocal()
370+
>>> mydata.number = 42
371+
>>> mydata.color = 'red'
372+
373+
So, the separate thread::
374+
375+
>>> thread = threading.Thread(target=f)
376+
>>> thread.start()
377+
>>> thread.join()
378+
379+
affects what we see::
380+
381+
>>> mydata.number
382+
11
271383

272384

273385
.. class:: local()
274386

275387
A class that represents thread-local data.
276388

277-
For more details and extensive examples, see the documentation string of the
278-
:mod:`!_threading_local` module: :source:`Lib/_threading_local.py`.
279-
280389

281390
.. _thread-objects:
282391

_sources/library/typing.rst.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,6 +1098,12 @@ These can be used as types in annotations. They all support subscription using
10981098

10991099
Union[Union[int, str], float] == Union[int, str, float]
11001100

1101+
However, this does not apply to unions referenced through a type
1102+
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
1103+
1104+
type A = Union[int, str]
1105+
Union[A, float] != Union[int, str, float]
1106+
11011107
* Unions of a single argument vanish, e.g.::
11021108

11031109
Union[int] == int # The constructor actually returns int
@@ -1222,6 +1228,32 @@ These can be used as types in annotations. They all support subscription using
12221228
is allowed as type argument to ``Literal[...]``, but type checkers may
12231229
impose restrictions. See :pep:`586` for more details about literal types.
12241230

1231+
Additional details:
1232+
1233+
* The arguments must be literal values and there must be at least one.
1234+
1235+
* Nested ``Literal`` types are flattened, e.g.::
1236+
1237+
assert Literal[Literal[1, 2], 3] == Literal[1, 2, 3]
1238+
1239+
However, this does not apply to ``Literal`` types referenced through a type
1240+
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
1241+
1242+
type A = Literal[1, 2]
1243+
assert Literal[A, 3] != Literal[1, 2, 3]
1244+
1245+
* Redundant arguments are skipped, e.g.::
1246+
1247+
assert Literal[1, 2, 1] == Literal[1, 2]
1248+
1249+
* When comparing literals, the argument order is ignored, e.g.::
1250+
1251+
assert Literal[1, 2] == Literal[2, 1]
1252+
1253+
* You cannot subclass or instantiate a ``Literal``.
1254+
1255+
* You cannot write ``Literal[X][Y]``.
1256+
12251257
.. versionadded:: 3.8
12261258

12271259
.. versionchanged:: 3.9.1
@@ -1392,6 +1424,14 @@ These can be used as types in annotations. They all support subscription using
13921424
int, ValueRange(3, 10), ctype("char")
13931425
]
13941426

1427+
However, this does not apply to ``Annotated`` types referenced through a type
1428+
alias, to avoid forcing evaluation of the underlying :class:`TypeAliasType`::
1429+
1430+
type From3To10[T] = Annotated[T, ValueRange(3, 10)]
1431+
assert Annotated[From3To10[int], ctype("char")] != Annotated[
1432+
int, ValueRange(3, 10), ctype("char")
1433+
]
1434+
13951435
Duplicated metadata elements are not removed::
13961436

13971437
assert Annotated[int, ValueRange(3, 10)] != Annotated[

about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ <h3>瀏覽</h3>
320320
<a href="https://www.python.org/psf/donations/">Please donate.</a>
321321
<br>
322322
<br>
323-
最後更新於 5月 04, 2025 (08:31 UTC)。
323+
最後更新於 5月 06, 2025 (02:42 UTC)。
324324

325325
<a href="/bugs.html">Found a bug</a>?
326326

bugs.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ <h2>說明文件的錯誤<a class="headerlink" href="#documentation-bugs" title=
231231
</section>
232232
<section id="getting-started-contributing-to-python-yourself">
233233
<span id="contributing-to-python"></span><h2>開始讓自己貢獻 Python<a class="headerlink" href="#getting-started-contributing-to-python-yourself" title="連結到這個標頭"></a></h2>
234-
<p>除了只是回報你所發現的錯誤之外,同樣也歡迎你提交修正它們的修補程式 (patch)。你可以在 <a class="reference external" href="https://mail.python.org/mailman3/lists/core-mentorship.python.org/">Python 開發者指南</a>中找到如何開始修補 Python 的更多資訊。如果你有任何問題,<a class="reference external" href="https://devguide.python.org/">核心導師郵寄清單</a>是一個友善的地方,你可以在那裡得到,關於 Python 修正錯誤的過程中,所有問題的答案。</p>
234+
<p>除了只是回報你所發現的錯誤之外,同樣也歡迎你提交修正它們的修補程式 (patch)。你可以在 <a class="reference external" href="https://devguide.python.org/">Python 開發者指南</a>中找到如何開始修補 Python 的更多資訊。如果你有任何問題,<a class="reference external" href="https://mail.python.org/mailman3/lists/core-mentorship.python.org/">核心導師郵寄清單</a>是一個友善的地方,你可以在那裡得到,關於 Python 修正錯誤的過程中,所有問題的答案。</p>
235235
</section>
236236
</section>
237237

@@ -359,7 +359,7 @@ <h3>瀏覽</h3>
359359
<a href="https://www.python.org/psf/donations/">Please donate.</a>
360360
<br>
361361
<br>
362-
最後更新於 5月 04, 2025 (08:31 UTC)。
362+
最後更新於 5月 06, 2025 (02:42 UTC)。
363363

364364
<a href="/bugs.html">Found a bug</a>?
365365

c-api/abstract.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ <h3>瀏覽</h3>
329329
<a href="https://www.python.org/psf/donations/">Please donate.</a>
330330
<br>
331331
<br>
332-
最後更新於 5月 04, 2025 (08:31 UTC)。
332+
最後更新於 5月 06, 2025 (02:42 UTC)。
333333

334334
<a href="/bugs.html">Found a bug</a>?
335335

c-api/allocation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ <h3>瀏覽</h3>
350350
<a href="https://www.python.org/psf/donations/">Please donate.</a>
351351
<br>
352352
<br>
353-
最後更新於 5月 04, 2025 (08:31 UTC)。
353+
最後更新於 5月 06, 2025 (02:42 UTC)。
354354

355355
<a href="/bugs.html">Found a bug</a>?
356356

c-api/apiabiversion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ <h3>瀏覽</h3>
376376
<a href="https://www.python.org/psf/donations/">Please donate.</a>
377377
<br>
378378
<br>
379-
最後更新於 5月 04, 2025 (08:31 UTC)。
379+
最後更新於 5月 06, 2025 (02:42 UTC)。
380380

381381
<a href="/bugs.html">Found a bug</a>?
382382

c-api/arg.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ <h3>瀏覽</h3>
931931
<a href="https://www.python.org/psf/donations/">Please donate.</a>
932932
<br>
933933
<br>
934-
最後更新於 5月 04, 2025 (08:31 UTC)。
934+
最後更新於 5月 06, 2025 (02:42 UTC)。
935935

936936
<a href="/bugs.html">Found a bug</a>?
937937

c-api/bool.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ <h3>瀏覽</h3>
341341
<a href="https://www.python.org/psf/donations/">Please donate.</a>
342342
<br>
343343
<br>
344-
最後更新於 5月 04, 2025 (08:31 UTC)。
344+
最後更新於 5月 06, 2025 (02:42 UTC)。
345345

346346
<a href="/bugs.html">Found a bug</a>?
347347

c-api/buffer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ <h3>瀏覽</h3>
10221022
<a href="https://www.python.org/psf/donations/">Please donate.</a>
10231023
<br>
10241024
<br>
1025-
最後更新於 5月 04, 2025 (08:31 UTC)。
1025+
最後更新於 5月 06, 2025 (02:42 UTC)。
10261026

10271027
<a href="/bugs.html">Found a bug</a>?
10281028

c-api/bytearray.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ <h3>瀏覽</h3>
400400
<a href="https://www.python.org/psf/donations/">Please donate.</a>
401401
<br>
402402
<br>
403-
最後更新於 5月 04, 2025 (08:31 UTC)。
403+
最後更新於 5月 06, 2025 (02:42 UTC)。
404404

405405
<a href="/bugs.html">Found a bug</a>?
406406

c-api/bytes.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ <h3>瀏覽</h3>
521521
<a href="https://www.python.org/psf/donations/">Please donate.</a>
522522
<br>
523523
<br>
524-
最後更新於 5月 04, 2025 (08:31 UTC)。
524+
最後更新於 5月 06, 2025 (02:42 UTC)。
525525

526526
<a href="/bugs.html">Found a bug</a>?
527527

c-api/call.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ <h3>瀏覽</h3>
652652
<a href="https://www.python.org/psf/donations/">Please donate.</a>
653653
<br>
654654
<br>
655-
最後更新於 5月 04, 2025 (08:31 UTC)。
655+
最後更新於 5月 06, 2025 (02:42 UTC)。
656656

657657
<a href="/bugs.html">Found a bug</a>?
658658

c-api/capsule.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ <h3>瀏覽</h3>
441441
<a href="https://www.python.org/psf/donations/">Please donate.</a>
442442
<br>
443443
<br>
444-
最後更新於 5月 04, 2025 (08:31 UTC)。
444+
最後更新於 5月 06, 2025 (02:42 UTC)。
445445

446446
<a href="/bugs.html">Found a bug</a>?
447447

c-api/cell.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ <h3>瀏覽</h3>
341341
<a href="https://www.python.org/psf/donations/">Please donate.</a>
342342
<br>
343343
<br>
344-
最後更新於 5月 04, 2025 (08:31 UTC)。
344+
最後更新於 5月 06, 2025 (02:42 UTC)。
345345

346346
<a href="/bugs.html">Found a bug</a>?
347347

c-api/code.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ <h3>瀏覽</h3>
606606
<a href="https://www.python.org/psf/donations/">Please donate.</a>
607607
<br>
608608
<br>
609-
最後更新於 5月 04, 2025 (08:31 UTC)。
609+
最後更新於 5月 06, 2025 (02:42 UTC)。
610610

611611
<a href="/bugs.html">Found a bug</a>?
612612

c-api/codec.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ <h3>瀏覽</h3>
445445
<a href="https://www.python.org/psf/donations/">Please donate.</a>
446446
<br>
447447
<br>
448-
最後更新於 5月 04, 2025 (08:31 UTC)。
448+
最後更新於 5月 06, 2025 (02:42 UTC)。
449449

450450
<a href="/bugs.html">Found a bug</a>?
451451

c-api/complex.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ <h3>瀏覽</h3>
448448
<a href="https://www.python.org/psf/donations/">Please donate.</a>
449449
<br>
450450
<br>
451-
最後更新於 5月 04, 2025 (08:31 UTC)。
451+
最後更新於 5月 06, 2025 (02:42 UTC)。
452452

453453
<a href="/bugs.html">Found a bug</a>?
454454

c-api/concrete.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ <h3>瀏覽</h3>
465465
<a href="https://www.python.org/psf/donations/">Please donate.</a>
466466
<br>
467467
<br>
468-
最後更新於 5月 04, 2025 (08:31 UTC)。
468+
最後更新於 5月 06, 2025 (02:42 UTC)。
469469

470470
<a href="/bugs.html">Found a bug</a>?
471471

c-api/contextvars.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ <h3>瀏覽</h3>
451451
<a href="https://www.python.org/psf/donations/">Please donate.</a>
452452
<br>
453453
<br>
454-
最後更新於 5月 04, 2025 (08:31 UTC)。
454+
最後更新於 5月 06, 2025 (02:42 UTC)。
455455

456456
<a href="/bugs.html">Found a bug</a>?
457457

0 commit comments

Comments
 (0)