Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/worker.py @ 48961:df56e6bd37f6
py3: use pickle directly
pycompat.pickle abstracted over the different pickle modules in
Python 2 and 3. Now that we're Python 3 only, it is safe to use the
`pickle` module directly. So this commit does that.
As part of this we remove the rules from check-code.py that were
forbidden direct pickle module use.
We retain the `util.pickle` symbol for backwards compatibility, just
in case some extensions were using it.
Differential Revision: https://phab.mercurial-scm.org/D12249
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 01 Mar 2022 20:29:03 -0800 |
parents | d4ba4d51f85f |
children | 6000f5b25c9b |
comparison
equal
deleted
inserted
replaced
48960:57b58413dad1 | 48961:df56e6bd37f6 |
---|---|
7 | 7 |
8 from __future__ import absolute_import | 8 from __future__ import absolute_import |
9 | 9 |
10 import errno | 10 import errno |
11 import os | 11 import os |
12 import pickle | |
12 import signal | 13 import signal |
13 import sys | 14 import sys |
14 import threading | 15 import threading |
15 import time | 16 import time |
16 | 17 |
25 from . import ( | 26 from . import ( |
26 encoding, | 27 encoding, |
27 error, | 28 error, |
28 pycompat, | 29 pycompat, |
29 scmutil, | 30 scmutil, |
30 util, | |
31 ) | 31 ) |
32 | 32 |
33 | 33 |
34 def countcpus(): | 34 def countcpus(): |
35 '''try to count the number of CPUs on the system''' | 35 '''try to count the number of CPUs on the system''' |
254 for r, w in pipes[:-1]: | 254 for r, w in pipes[:-1]: |
255 os.close(r) | 255 os.close(r) |
256 os.close(w) | 256 os.close(w) |
257 os.close(rfd) | 257 os.close(rfd) |
258 for result in func(*(staticargs + (pargs,))): | 258 for result in func(*(staticargs + (pargs,))): |
259 os.write(wfd, util.pickle.dumps(result)) | 259 os.write(wfd, pickle.dumps(result)) |
260 return 0 | 260 return 0 |
261 | 261 |
262 ret = scmutil.callcatch(ui, workerfunc) | 262 ret = scmutil.callcatch(ui, workerfunc) |
263 except: # parent re-raises, child never returns | 263 except: # parent re-raises, child never returns |
264 if os.getpid() == parentpid: | 264 if os.getpid() == parentpid: |
290 try: | 290 try: |
291 openpipes = len(pipes) | 291 openpipes = len(pipes) |
292 while openpipes > 0: | 292 while openpipes > 0: |
293 for key, events in selector.select(): | 293 for key, events in selector.select(): |
294 try: | 294 try: |
295 res = util.pickle.load(_blockingreader(key.fileobj)) | 295 res = pickle.load(_blockingreader(key.fileobj)) |
296 if hasretval and res[0]: | 296 if hasretval and res[0]: |
297 retval.update(res[1]) | 297 retval.update(res[1]) |
298 else: | 298 else: |
299 yield res | 299 yield res |
300 except EOFError: | 300 except EOFError: |