Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit150cea1

Browse files
authored
Merge branch 'main' into multi_inputs
2 parentsba26b80 +81a9b53 commit150cea1

14 files changed

+531
-136
lines changed

‎Doc/library/multiprocessing.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,35 +380,40 @@ However, if you really do need to use some shared data then
380380
proxies.
381381

382382
A manager returned by:func:`Manager` will support types
383-
:class:`list`,:class:`dict`,:class:`~managers.Namespace`,:class:`Lock`,
383+
:class:`list`,:class:`dict`,:class:`set`,:class:`~managers.Namespace`,:class:`Lock`,
384384
:class:`RLock`,:class:`Semaphore`,:class:`BoundedSemaphore`,
385385
:class:`Condition`,:class:`Event`,:class:`Barrier`,
386386
:class:`Queue`,:class:`Value` and:class:`Array`. For example, ::
387387

388388
from multiprocessing import Process, Manager
389389

390-
def f(d, l):
390+
def f(d, l, s):
391391
d[1] = '1'
392392
d['2'] = 2
393393
d[0.25] = None
394394
l.reverse()
395+
s.add('a')
396+
s.add('b')
395397

396398
if __name__ == '__main__':
397399
with Manager() as manager:
398400
d = manager.dict()
399401
l = manager.list(range(10))
402+
s = manager.set()
400403

401-
p = Process(target=f, args=(d, l))
404+
p = Process(target=f, args=(d, l, s))
402405
p.start()
403406
p.join()
404407

405408
print(d)
406409
print(l)
410+
print(s)
407411

408412
will print ::
409413

410414
{0.25: None, 1: '1', '2': 2}
411415
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
416+
{'a', 'b'}
412417

413418
Server process managers are more flexible than using shared memory objects
414419
because they can be made to support arbitrary object types. Also, a single
@@ -1942,6 +1947,15 @@ their parent process exits. The manager classes are defined in the
19421947

19431948
Create a shared:class:`list` object and return a proxy for it.
19441949

1950+
..method::set()
1951+
set(sequence)
1952+
set(mapping)
1953+
1954+
Create a shared:class:`set` object and return a proxy for it.
1955+
1956+
..versionadded::next
1957+
:class:`set` support was added.
1958+
19451959
..versionchanged::3.6
19461960
Shared objects are capable of being nested. For example, a shared
19471961
container object such as a shared list can contain other shared objects

‎Doc/whatsnew/3.14.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,11 @@ multiprocessing
700700

701701
(Contributed by Roy Hyunjin Han for:gh:`103134`.)
702702

703+
* Add support for shared:class:`set` objects via
704+
:meth:`SyncManager.set() <multiprocessing.managers.SyncManager.set>`.
705+
The:func:`set` in:func:`multiprocessing.Manager` method is now available.
706+
(Contributed by Mingyu Park in:gh:`129949`.)
707+
703708

704709
operator
705710
--------

‎Lib/_pydatetime.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
__all__= ("date","datetime","time","timedelta","timezone","tzinfo",
44
"MINYEAR","MAXYEAR","UTC")
55

6+
__name__="datetime"
7+
68

79
importtimeas_time
810
importmathas_math
@@ -14,10 +16,10 @@ def _cmp(x, y):
1416

1517
def_get_class_module(self):
1618
module_name=self.__class__.__module__
17-
ifmodule_name=='_pydatetime':
18-
return'datetime'
19+
ifmodule_name=='datetime':
20+
return'datetime.'
1921
else:
20-
returnmodule_name
22+
return''
2123

2224
MINYEAR=1
2325
MAXYEAR=9999
@@ -767,9 +769,9 @@ def __repr__(self):
767769
args.append("microseconds=%d"%self._microseconds)
768770
ifnotargs:
769771
args.append('0')
770-
return"%s.%s(%s)"% (_get_class_module(self),
771-
self.__class__.__qualname__,
772-
', '.join(args))
772+
return"%s%s(%s)"% (_get_class_module(self),
773+
self.__class__.__qualname__,
774+
', '.join(args))
773775

774776
def__str__(self):
775777
mm,ss=divmod(self._seconds,60)
@@ -1082,11 +1084,11 @@ def __repr__(self):
10821084
>>> repr(d)
10831085
'datetime.date(2010, 1, 1)'
10841086
"""
1085-
return"%s.%s(%d, %d, %d)"% (_get_class_module(self),
1086-
self.__class__.__qualname__,
1087-
self._year,
1088-
self._month,
1089-
self._day)
1087+
return"%s%s(%d, %d, %d)"% (_get_class_module(self),
1088+
self.__class__.__qualname__,
1089+
self._year,
1090+
self._month,
1091+
self._day)
10901092
# XXX These shouldn't depend on time.localtime(), because that
10911093
# clips the usable dates to [1970 .. 2038). At least ctime() is
10921094
# easily done without using strftime() -- that's better too because
@@ -1586,7 +1588,7 @@ def __repr__(self):
15861588
s=", %d"%self._second
15871589
else:
15881590
s=""
1589-
s="%s.%s(%d, %d%s)"% (_get_class_module(self),
1591+
s="%s%s(%d, %d%s)"% (_get_class_module(self),
15901592
self.__class__.__qualname__,
15911593
self._hour,self._minute,s)
15921594
ifself._tzinfoisnotNone:
@@ -2162,9 +2164,9 @@ def __repr__(self):
21622164
delL[-1]
21632165
ifL[-1]==0:
21642166
delL[-1]
2165-
s="%s.%s(%s)"% (_get_class_module(self),
2166-
self.__class__.__qualname__,
2167-
", ".join(map(str,L)))
2167+
s="%s%s(%s)"% (_get_class_module(self),
2168+
self.__class__.__qualname__,
2169+
", ".join(map(str,L)))
21682170
ifself._tzinfoisnotNone:
21692171
asserts[-1:]==")"
21702172
s=s[:-1]+", tzinfo=%r"%self._tzinfo+")"
@@ -2461,12 +2463,12 @@ def __repr__(self):
24612463
ifselfisself.utc:
24622464
return'datetime.timezone.utc'
24632465
ifself._nameisNone:
2464-
return"%s.%s(%r)"% (_get_class_module(self),
2465-
self.__class__.__qualname__,
2466-
self._offset)
2467-
return"%s.%s(%r, %r)"% (_get_class_module(self),
2468-
self.__class__.__qualname__,
2469-
self._offset,self._name)
2466+
return"%s%s(%r)"% (_get_class_module(self),
2467+
self.__class__.__qualname__,
2468+
self._offset)
2469+
return"%s%s(%r, %r)"% (_get_class_module(self),
2470+
self.__class__.__qualname__,
2471+
self._offset,self._name)
24702472

24712473
def__str__(self):
24722474
returnself.tzname(None)

‎Lib/_pyrepl/base_eventqueue.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Copyright 2000-2008 Michael Hudson-Doyle <micahel@gmail.com>
2+
# Armin Rigo
3+
#
4+
# All Rights Reserved
5+
#
6+
#
7+
# Permission to use, copy, modify, and distribute this software and
8+
# its documentation for any purpose is hereby granted without fee,
9+
# provided that the above copyright notice appear in all copies and
10+
# that both that copyright notice and this permission notice appear in
11+
# supporting documentation.
12+
#
13+
# THE AUTHOR MICHAEL HUDSON DISCLAIMS ALL WARRANTIES WITH REGARD TO
14+
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15+
# AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
16+
# INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
17+
# RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
18+
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
19+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20+
21+
"""
22+
OS-independent base for an event and VT sequence scanner
23+
24+
See unix_eventqueue and windows_eventqueue for subclasses.
25+
"""
26+
27+
fromcollectionsimportdeque
28+
29+
from .importkeymap
30+
from .consoleimportEvent
31+
from .traceimporttrace
32+
33+
classBaseEventQueue:
34+
def__init__(self,encoding:str,keymap_dict:dict[bytes,str])->None:
35+
self.compiled_keymap=keymap.compile_keymap(keymap_dict)
36+
self.keymap=self.compiled_keymap
37+
trace("keymap {k!r}",k=self.keymap)
38+
self.encoding=encoding
39+
self.events:deque[Event]=deque()
40+
self.buf=bytearray()
41+
42+
defget(self)->Event|None:
43+
"""
44+
Retrieves the next event from the queue.
45+
"""
46+
ifself.events:
47+
returnself.events.popleft()
48+
else:
49+
returnNone
50+
51+
defempty(self)->bool:
52+
"""
53+
Checks if the queue is empty.
54+
"""
55+
returnnotself.events
56+
57+
defflush_buf(self)->bytearray:
58+
"""
59+
Flushes the buffer and returns its contents.
60+
"""
61+
old=self.buf
62+
self.buf=bytearray()
63+
returnold
64+
65+
definsert(self,event:Event)->None:
66+
"""
67+
Inserts an event into the queue.
68+
"""
69+
trace('added event {event}',event=event)
70+
self.events.append(event)
71+
72+
defpush(self,char:int|bytes)->None:
73+
"""
74+
Processes a character by updating the buffer and handling special key mappings.
75+
"""
76+
ord_char=charifisinstance(char,int)elseord(char)
77+
char=bytes(bytearray((ord_char,)))
78+
self.buf.append(ord_char)
79+
ifcharinself.keymap:
80+
ifself.keymapisself.compiled_keymap:
81+
# sanity check, buffer is empty when a special key comes
82+
assertlen(self.buf)==1
83+
k=self.keymap[char]
84+
trace('found map {k!r}',k=k)
85+
ifisinstance(k,dict):
86+
self.keymap=k
87+
else:
88+
self.insert(Event('key',k,self.flush_buf()))
89+
self.keymap=self.compiled_keymap
90+
91+
elifself.bufandself.buf[0]==27:# escape
92+
# escape sequence not recognized by our keymap: propagate it
93+
# outside so that i can be recognized as an M-... key (see also
94+
# the docstring in keymap.py
95+
trace('unrecognized escape sequence, propagating...')
96+
self.keymap=self.compiled_keymap
97+
self.insert(Event('key','\033',bytearray(b'\033')))
98+
for_cinself.flush_buf()[1:]:
99+
self.push(_c)
100+
101+
else:
102+
try:
103+
decoded=bytes(self.buf).decode(self.encoding)
104+
exceptUnicodeError:
105+
return
106+
else:
107+
self.insert(Event('key',decoded,self.flush_buf()))
108+
self.keymap=self.compiled_keymap

‎Lib/_pyrepl/unix_eventqueue.py

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@
1818
# CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1919
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2020

21-
fromcollectionsimportdeque
22-
23-
from .importkeymap
24-
from .consoleimportEvent
2521
from .importcurses
2622
from .traceimporttrace
23+
from .base_eventqueueimportBaseEventQueue
2724
fromtermiosimporttcgetattr,VERASE
2825
importos
2926

@@ -70,83 +67,10 @@ def get_terminal_keycodes() -> dict[bytes, str]:
7067
keycodes.update(CTRL_ARROW_KEYCODES)
7168
returnkeycodes
7269

73-
classEventQueue:
70+
classEventQueue(BaseEventQueue):
7471
def__init__(self,fd:int,encoding:str)->None:
75-
self.keycodes=get_terminal_keycodes()
72+
keycodes=get_terminal_keycodes()
7673
ifos.isatty(fd):
7774
backspace=tcgetattr(fd)[6][VERASE]
78-
self.keycodes[backspace]="backspace"
79-
self.compiled_keymap=keymap.compile_keymap(self.keycodes)
80-
self.keymap=self.compiled_keymap
81-
trace("keymap {k!r}",k=self.keymap)
82-
self.encoding=encoding
83-
self.events:deque[Event]=deque()
84-
self.buf=bytearray()
85-
86-
defget(self)->Event|None:
87-
"""
88-
Retrieves the next event from the queue.
89-
"""
90-
ifself.events:
91-
returnself.events.popleft()
92-
else:
93-
returnNone
94-
95-
defempty(self)->bool:
96-
"""
97-
Checks if the queue is empty.
98-
"""
99-
returnnotself.events
100-
101-
defflush_buf(self)->bytearray:
102-
"""
103-
Flushes the buffer and returns its contents.
104-
"""
105-
old=self.buf
106-
self.buf=bytearray()
107-
returnold
108-
109-
definsert(self,event:Event)->None:
110-
"""
111-
Inserts an event into the queue.
112-
"""
113-
trace('added event {event}',event=event)
114-
self.events.append(event)
115-
116-
defpush(self,char:int|bytes)->None:
117-
"""
118-
Processes a character by updating the buffer and handling special key mappings.
119-
"""
120-
ord_char=charifisinstance(char,int)elseord(char)
121-
char=bytes(bytearray((ord_char,)))
122-
self.buf.append(ord_char)
123-
ifcharinself.keymap:
124-
ifself.keymapisself.compiled_keymap:
125-
#sanity check, buffer is empty when a special key comes
126-
assertlen(self.buf)==1
127-
k=self.keymap[char]
128-
trace('found map {k!r}',k=k)
129-
ifisinstance(k,dict):
130-
self.keymap=k
131-
else:
132-
self.insert(Event('key',k,self.flush_buf()))
133-
self.keymap=self.compiled_keymap
134-
135-
elifself.bufandself.buf[0]==27:# escape
136-
# escape sequence not recognized by our keymap: propagate it
137-
# outside so that i can be recognized as an M-... key (see also
138-
# the docstring in keymap.py
139-
trace('unrecognized escape sequence, propagating...')
140-
self.keymap=self.compiled_keymap
141-
self.insert(Event('key','\033',bytearray(b'\033')))
142-
for_cinself.flush_buf()[1:]:
143-
self.push(_c)
144-
145-
else:
146-
try:
147-
decoded=bytes(self.buf).decode(self.encoding)
148-
exceptUnicodeError:
149-
return
150-
else:
151-
self.insert(Event('key',decoded,self.flush_buf()))
152-
self.keymap=self.compiled_keymap
75+
keycodes[backspace]="backspace"
76+
BaseEventQueue.__init__(self,encoding,keycodes)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp