Skip to content

Commit ddb3217

Browse files
Deploy preview for PR 1214 🛫
1 parent 2eaa524 commit ddb3217

File tree

586 files changed

+2180
-1598
lines changed

Some content is hidden

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

586 files changed

+2180
-1598
lines changed

pr-preview/pr-1214/_sources/howto/instrumentation.rst.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,84 @@ Available static markers
341341
.. versionadded:: 3.8
342342

343343

344+
C Entry Points
345+
^^^^^^^^^^^^^^
346+
347+
To simplify triggering of DTrace markers, Python's C API comes with a number
348+
of helper functions that mirror each static marker. On builds of Python without
349+
DTrace enabled, these do nothing.
350+
351+
In general, it is not necessary to call these yourself, as Python will do
352+
it for you.
353+
354+
.. list-table::
355+
:widths: 50 25 25
356+
:header-rows: 1
357+
358+
* * C API Function
359+
* Static Marker
360+
* Notes
361+
* * .. c:function:: void PyDTrace_LINE(const char *arg0, const char *arg1, int arg2)
362+
* :c:func:`!line`
363+
*
364+
* * .. c:function:: void PyDTrace_FUNCTION_ENTRY(const char *arg0, const char *arg1, int arg2)
365+
* :c:func:`!function__entry`
366+
*
367+
* * .. c:function:: void PyDTrace_FUNCTION_RETURN(const char *arg0, const char *arg1, int arg2)
368+
* :c:func:`!function__return`
369+
*
370+
* * .. c:function:: void PyDTrace_GC_START(int arg0)
371+
* :c:func:`!gc__start`
372+
*
373+
* * .. c:function:: void PyDTrace_GC_DONE(Py_ssize_t arg0)
374+
* :c:func:`!gc__done`
375+
*
376+
* * .. c:function:: void PyDTrace_INSTANCE_NEW_START(int arg0)
377+
* :c:func:`!instance__new__start`
378+
* Not used by Python
379+
* * .. c:function:: void PyDTrace_INSTANCE_NEW_DONE(int arg0)
380+
* :c:func:`!instance__new__done`
381+
* Not used by Python
382+
* * .. c:function:: void PyDTrace_INSTANCE_DELETE_START(int arg0)
383+
* :c:func:`!instance__delete__start`
384+
* Not used by Python
385+
* * .. c:function:: void PyDTrace_INSTANCE_DELETE_DONE(int arg0)
386+
* :c:func:`!instance__delete__done`
387+
* Not used by Python
388+
* * .. c:function:: void PyDTrace_IMPORT_FIND_LOAD_START(const char *arg0)
389+
* :c:func:`!import__find__load__start`
390+
*
391+
* * .. c:function:: void PyDTrace_IMPORT_FIND_LOAD_DONE(const char *arg0, int arg1)
392+
* :c:func:`!import__find__load__done`
393+
*
394+
* * .. c:function:: void PyDTrace_AUDIT(const char *arg0, void *arg1)
395+
* :c:func:`!audit`
396+
*
397+
398+
399+
C Probing Checks
400+
^^^^^^^^^^^^^^^^
401+
402+
.. c:function:: int PyDTrace_LINE_ENABLED(void)
403+
.. c:function:: int PyDTrace_FUNCTION_ENTRY_ENABLED(void)
404+
.. c:function:: int PyDTrace_FUNCTION_RETURN_ENABLED(void)
405+
.. c:function:: int PyDTrace_GC_START_ENABLED(void)
406+
.. c:function:: int PyDTrace_GC_DONE_ENABLED(void)
407+
.. c:function:: int PyDTrace_INSTANCE_NEW_START_ENABLED(void)
408+
.. c:function:: int PyDTrace_INSTANCE_NEW_DONE_ENABLED(void)
409+
.. c:function:: int PyDTrace_INSTANCE_DELETE_START_ENABLED(void)
410+
.. c:function:: int PyDTrace_INSTANCE_DELETE_DONE_ENABLED(void)
411+
.. c:function:: int PyDTrace_IMPORT_FIND_LOAD_START_ENABLED(void)
412+
.. c:function:: int PyDTrace_IMPORT_FIND_LOAD_DONE_ENABLED(void)
413+
.. c:function:: int PyDTrace_AUDIT_ENABLED(void)
414+
415+
All calls to ``PyDTrace`` functions must be guarded by a call to one
416+
of these functions. This allows Python to minimize performance impact
417+
when probing is disabled.
418+
419+
On builds without DTrace enabled, these functions do nothing and return
420+
``0``.
421+
344422
SystemTap Tapsets
345423
-----------------
346424

pr-preview/pr-1214/_sources/library/argparse.rst.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,8 @@ The add_argument() method
691691

692692
* deprecated_ - Whether or not use of the argument is deprecated.
693693

694+
The method returns an :class:`Action` object representing the argument.
695+
694696
The following sections describe how each of these are used.
695697

696698

pr-preview/pr-1214/_sources/library/stdtypes.rst.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3478,6 +3478,11 @@ The representation of bytearray objects uses the bytes literal format
34783478
``bytearray([46, 46, 46])``. You can always convert a bytearray object into
34793479
a list of integers using ``list(b)``.
34803480

3481+
.. seealso::
3482+
3483+
For detailed information on thread-safety guarantees for :class:`bytearray`
3484+
objects, see :ref:`thread-safety-bytearray`.
3485+
34813486

34823487
.. _bytes-methods:
34833488

pr-preview/pr-1214/_sources/library/threadsafety.rst.txt

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,104 @@ atomic:
447447
448448
Consider external synchronization when sharing :class:`set` instances
449449
across threads. See :ref:`freethreading-python-howto` for more information.
450+
451+
452+
.. _thread-safety-bytearray:
453+
454+
Thread safety for bytearray objects
455+
===================================
456+
457+
The :func:`len` function is lock-free and :term:`atomic <atomic operation>`.
458+
459+
Concatenation and comparisons use the buffer protocol, which prevents
460+
resizing but does not hold the per-object lock. These operations may
461+
observe intermediate states from concurrent modifications:
462+
463+
.. code-block::
464+
:class: maybe
465+
466+
ba + other # may observe concurrent writes
467+
ba == other # may observe concurrent writes
468+
ba < other # may observe concurrent writes
469+
470+
All other operations from here on hold the per-object lock.
471+
472+
Reading a single element or slice is safe to call from multiple threads:
473+
474+
.. code-block::
475+
:class: good
476+
477+
ba[i] # bytearray.__getitem__
478+
ba[i:j] # slice
479+
480+
The following operations are safe to call from multiple threads and will
481+
not corrupt the bytearray:
482+
483+
.. code-block::
484+
:class: good
485+
486+
ba[i] = x # write single byte
487+
ba[i:j] = values # write slice
488+
ba.append(x) # append single byte
489+
ba.extend(other) # extend with iterable
490+
ba.insert(i, x) # insert single byte
491+
ba.pop() # remove and return last byte
492+
ba.pop(i) # remove and return byte at index
493+
ba.remove(x) # remove first occurrence
494+
ba.reverse() # reverse in place
495+
ba.clear() # remove all bytes
496+
497+
Slice assignment locks both objects when *values* is a :class:`bytearray`:
498+
499+
.. code-block::
500+
:class: good
501+
502+
ba[i:j] = other_bytearray # both locked
503+
504+
The following operations return new objects and hold the per-object lock
505+
for the duration:
506+
507+
.. code-block::
508+
:class: good
509+
510+
ba.copy() # returns a shallow copy
511+
ba * n # repeat into new bytearray
512+
513+
The membership test holds the lock for its duration:
514+
515+
.. code-block::
516+
:class: good
517+
518+
x in ba # bytearray.__contains__
519+
520+
All other bytearray methods (such as :meth:`~bytearray.find`,
521+
:meth:`~bytearray.replace`, :meth:`~bytearray.split`,
522+
:meth:`~bytearray.decode`, etc.) hold the per-object lock for their
523+
duration.
524+
525+
Operations that involve multiple accesses, as well as iteration, are never
526+
atomic:
527+
528+
.. code-block::
529+
:class: bad
530+
531+
# NOT atomic: check-then-act
532+
if x in ba:
533+
ba.remove(x)
534+
535+
# NOT thread-safe: iteration while modifying
536+
for byte in ba:
537+
process(byte) # another thread may modify ba
538+
539+
To safely iterate over a bytearray that may be modified by another
540+
thread, iterate over a copy:
541+
542+
.. code-block::
543+
:class: good
544+
545+
# Make a copy to iterate safely
546+
for byte in ba.copy():
547+
process(byte)
548+
549+
Consider external synchronization when sharing :class:`bytearray` instances
550+
across threads. See :ref:`freethreading-python-howto` for more information.

pr-preview/pr-1214/about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ <h3>導航</h3>
356356
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
357357
<br>
358358
<br>
359-
最後更新於 3月 15, 2026 (00:28 UTC)。
359+
最後更新於 3月 16, 2026 (00:28 UTC)。
360360

361361
<a href="/bugs.html">發現 bug</a>
362362

pr-preview/pr-1214/bugs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ <h3>導航</h3>
393393
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
394394
<br>
395395
<br>
396-
最後更新於 3月 15, 2026 (00:28 UTC)。
396+
最後更新於 3月 16, 2026 (00:28 UTC)。
397397

398398
<a href="/bugs.html">發現 bug</a>
399399

pr-preview/pr-1214/c-api/abstract.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ <h3>導航</h3>
365365
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
366366
<br>
367367
<br>
368-
最後更新於 3月 15, 2026 (00:28 UTC)。
368+
最後更新於 3月 16, 2026 (00:28 UTC)。
369369

370370
<a href="/bugs.html">發現 bug</a>
371371

pr-preview/pr-1214/c-api/allocation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ <h3>導航</h3>
574574
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
575575
<br>
576576
<br>
577-
最後更新於 3月 15, 2026 (00:28 UTC)。
577+
最後更新於 3月 16, 2026 (00:28 UTC)。
578578

579579
<a href="/bugs.html">發現 bug</a>
580580

pr-preview/pr-1214/c-api/apiabiversion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ <h3>導航</h3>
514514
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
515515
<br>
516516
<br>
517-
最後更新於 3月 15, 2026 (00:28 UTC)。
517+
最後更新於 3月 16, 2026 (00:28 UTC)。
518518

519519
<a href="/bugs.html">發現 bug</a>
520520

pr-preview/pr-1214/c-api/arg.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ <h3>導航</h3>
996996
<a href="https://www.python.org/psf/donations/">敬請捐贈。</a>
997997
<br>
998998
<br>
999-
最後更新於 3月 15, 2026 (00:28 UTC)。
999+
最後更新於 3月 16, 2026 (00:28 UTC)。
10001000

10011001
<a href="/bugs.html">發現 bug</a>
10021002

0 commit comments

Comments
 (0)