Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
Commitc0f5de9
committed
Allow PyErr_CheckSignals to be called without holding the GIL.
Compiled-code modules that implement time-consuming operations thatdon’t require manipulating Python objects, are supposed to callPyErr_CheckSignals frequently throughout each such operation, so thatif the user interrupts the operation with control-C, it is cancelledpromptly. In the normal case where no signals are pending,PyErr_CheckSignals is cheap; however, callers must hold the GIL,and compiled-code modules that implement time-consuming operationsare also supposed to release the GIL during each such operation.The overhead of reclaiming the GIL in order to call PyErr_CheckSignals,and then releasing it again, sufficiently often for reasonable userresponsiveness, can be substantial.If my understanding of the thread-state rules is correct,PyErr_CheckSignals only *needs* the GIL if it has work to do.*Checking* whether there is a pending signal, or a pending requestto run the cycle collector, requires only a couple of atomic loads.Therefore: Reorganize the logic of PyErr_CheckSignals and its closerelatives (_PyErr_CheckSignals and _PyErr_CheckSignalsTstate) so thatall the “do we have anything to do” checks are done in a batch beforeanything that needs the GIL. If any of them are true, acquire the GIL,repeat the check (because another thread could have stolen the eventwhile we were waiting for the GIL), and then actually do the work,enabling callers to *not* hold the GIL.(There are some fine details here that I’d really appreciate a secondpair of eyes on — see the comments in the new functions_PyErr_CheckSignalsHoldingGIL and _PyErr_CheckSignalsNoGIL.)1 parent9434709 commitc0f5de9
File tree
4 files changed
+125
-44
lines changed- Doc/c-api
- Misc/NEWS.d/next/C_API
- Modules
4 files changed
+125
-44
lines changedLines changed: 43 additions & 19 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
631 | 631 |
| |
632 | 632 |
| |
633 | 633 |
| |
| 634 | + | |
| 635 | + | |
634 | 636 |
| |
635 | 637 |
| |
636 | 638 |
| |
| |||
639 | 641 |
| |
640 | 642 |
| |
641 | 643 |
| |
642 |
| - | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
643 | 674 |
| |
644 |
| - | |
645 |
| - | |
646 |
| - | |
647 |
| - | |
648 |
| - | |
649 |
| - | |
650 |
| - | |
651 |
| - | |
652 |
| - | |
653 |
| - | |
654 |
| - | |
655 |
| - | |
656 |
| - | |
657 |
| - | |
658 |
| - | |
659 |
| - | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
660 | 678 |
| |
661 | 679 |
| |
662 |
| - | |
663 |
| - | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
664 | 685 |
| |
| 686 | + | |
| 687 | + | |
| 688 | + | |
665 | 689 |
| |
666 | 690 |
| |
667 | 691 |
| |
|
Lines changed: 5 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1045 | 1045 |
| |
1046 | 1046 |
| |
1047 | 1047 |
| |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
1048 | 1053 |
| |
1049 | 1054 |
| |
1050 | 1055 |
| |
|
Lines changed: 7 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + |
Lines changed: 70 additions & 25 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1759 | 1759 |
| |
1760 | 1760 |
| |
1761 | 1761 |
| |
1762 |
| - | |
1763 |
| - | |
1764 |
| - | |
1765 |
| - | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
1766 | 1767 |
| |
1767 |
| - | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
1768 | 1778 |
| |
1769 | 1779 |
| |
1770 | 1780 |
| |
| |||
1777 | 1787 |
| |
1778 | 1788 |
| |
1779 | 1789 |
| |
1780 |
| - | |
1781 |
| - | |
1782 |
| - | |
1783 |
| - | |
1784 |
| - | |
1785 |
| - | |
1786 |
| - | |
1787 |
| - | |
1788 |
| - | |
1789 |
| - | |
1790 |
| - | |
1791 |
| - | |
1792 |
| - | |
1793 |
| - | |
1794 |
| - | |
1795 |
| - | |
1796 |
| - | |
1797 |
| - | |
| 1790 | + | |
| 1791 | + | |
1798 | 1792 |
| |
1799 | 1793 |
| |
1800 | 1794 |
| |
| |||
1877 | 1871 |
| |
1878 | 1872 |
| |
1879 | 1873 |
| |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
1880 | 1899 |
| |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
1881 | 1905 |
| |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
1882 | 1919 |
| |
1883 | 1920 |
| |
1884 | 1921 |
| |
1885 |
| - | |
1886 |
| - | |
| 1922 | + | |
| 1923 | + | |
1887 | 1924 |
| |
1888 | 1925 |
| |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
| 1930 | + | |
| 1931 | + | |
| 1932 | + | |
| 1933 | + | |
1889 | 1934 |
| |
1890 | 1935 |
| |
1891 | 1936 |
| |
|
0 commit comments
Comments
(0)