Skip to content

Commit 614090b

Browse files
authored
Call os._exit() for faster shut down if using --fast-exit (#5569)
This can speed up self checking by about a second.
1 parent a0c2c1b commit 614090b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

mypy/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ def flush_errors(new_messages: List[str], serious: bool) -> None:
107107
from mypy.memprofile import print_memory_profile
108108
print_memory_profile()
109109

110+
code = 0
110111
if messages:
111112
code = 2 if blockers else 1
113+
if options.fast_exit:
114+
# Exit without freeing objects -- it's faster.
115+
#
116+
# NOTE: We don't flush all open files on exit (or run other destructors)!
117+
util.hard_exit(code)
118+
elif code:
112119
sys.exit(code)
113120

114121

@@ -613,6 +620,8 @@ def add_invertible_flag(flag: str,
613620
dest='shadow_file', action='append',
614621
help="When encountering SOURCE_FILE, read and type check "
615622
"the contents of SHADOW_FILE instead.")
623+
add_invertible_flag('--fast-exit', default=False, help=argparse.SUPPRESS,
624+
group=internals_group)
616625

617626
error_group = parser.add_argument_group(
618627
title='Error reporting',

mypy/options.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ def __init__(self) -> None:
211211
# if they don't have __init__.py.
212212
self.package_root = [] # type: List[str]
213213
self.cache_map = {} # type: Dict[str, Tuple[str, str]]
214+
# Don't properly free objects on exit, just kill the current process.
215+
self.fast_exit = False
214216

215217
def snapshot(self) -> object:
216218
"""Produce a comparable snapshot of this Option"""

mypy/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,13 @@ def replace_object_state(new: object, old: object, copy_dict: bool=False) -> Non
238238
def is_sub_path(path1: str, path2: str) -> bool:
239239
"""Given two paths, return if path1 is a sub-path of path2."""
240240
return pathlib.Path(path2) in pathlib.Path(path1).parents
241+
242+
243+
def hard_exit(status: int = 0) -> None:
244+
"""Kill the current process without fully cleaning up.
245+
246+
This can be quite a bit faster than a normal exit() since objects are not freed.
247+
"""
248+
sys.stdout.flush()
249+
sys.stderr.flush()
250+
os._exit(status)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy