Repository navigation
Commit a5bf5f3
gh-96471: Reimplement multiprocessing.Queue.shutdown()
Replace the pending-getter and pending-putter counters with a design
which does not need to know who is waiting:
* A count of the items accepted by put() in any process and not yet
received tells a getter whether the queue is really empty, including
the items still in another process's feeder thread buffer.
* shutdown() writes a single empty message to the pipe. The getter
which reads it writes it back, so every getter is woken in its turn,
and raises ShutDown only when nothing is outstanding.
* shutdown() releases the queue's semaphore once if the queue is full.
A putter which acquires it and finds the queue shut down releases it
again, waking the next one.
* shutdown(immediate=True) discards the items in the pipe and in every
feeder thread buffer, accounting for each of them. The unfinished
task count of a JoinableQueue only goes down by the number of items
discarded, as in queue.Queue.
Items put just before shutdown() are no longer lost, getters and
shutdown() itself no longer hang, and calling shutdown() again is
allowed, as in queue.Queue.
The tests are rewritten. Most of them also run on queue.Queue, through
the 'threads' and 'manager' types, to check the behaviour is the same.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>1 parent 11d4089 commit a5bf5f3
5 files changed
Lines changed: 651 additions & 584 deletions
File tree
- Doc
- library
- whatsnew
- Lib
- multiprocessing
- test
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
942 | 942 | | |
943 | 943 | | |
944 | 944 | | |
945 | | - | |
| 945 | + | |
946 | 946 | | |
947 | 947 | | |
948 | 948 | | |
| |||
979 | 979 | | |
980 | 980 | | |
981 | 981 | | |
982 | | - | |
| 982 | + | |
983 | 983 | | |
984 | | - | |
| 984 | + | |
| 985 | + | |
985 | 986 | | |
986 | 987 | | |
987 | 988 | | |
| |||
1001 | 1002 | | |
1002 | 1003 | | |
1003 | 1004 | | |
1004 | | - | |
| 1005 | + | |
| 1006 | + | |
1005 | 1007 | | |
1006 | | - | |
| 1008 | + | |
| 1009 | + | |
1007 | 1010 | | |
1008 | 1011 | | |
1009 | 1012 | | |
1010 | 1013 | | |
1011 | 1014 | | |
1012 | | - | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
1013 | 1039 | | |
1014 | | - | |
1015 | | - | |
1016 | | - | |
1017 | | - | |
1018 | | - | |
1019 | | - | |
| 1040 | + | |
| 1041 | + | |
1020 | 1042 | | |
1021 | | - | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
1022 | 1063 | | |
1023 | 1064 | | |
1024 | 1065 | | |
| |||
1122 | 1163 | | |
1123 | 1164 | | |
1124 | 1165 | | |
| 1166 | + | |
| 1167 | + | |
| 1168 | + | |
| 1169 | + | |
1125 | 1170 | | |
1126 | 1171 | | |
1127 | 1172 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
638 | 638 | | |
639 | 639 | | |
640 | 640 | | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
641 | 646 | | |
642 | 647 | | |
643 | 648 | | |
| |||
0 commit comments