Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion gazelle/python/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import concurrent.futures
import json
import os
import platform
import sys
from io import BytesIO
from tokenize import COMMENT, NAME, OP, STRING, tokenize
Expand Down Expand Up @@ -108,8 +109,19 @@ def parse(repo_root, rel_package_path, filename):
return output


def create_main_executor():
# We cannot use ProcessPoolExecutor on macOS, because the fork start method should be considered unsafe as it can
# lead to crashes of the subprocess as macOS system libraries may start threads. Meanwhile, the 'spawn' and
# 'forkserver' start methods generally cannot be used with “frozen” executables (i.e., Python zip file) on POSIX
# systems. Therefore, there is no good way to use ProcessPoolExecutor on macOS when we distribute this program with
# a zip file.
# Ref: https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
if platform.system() == "Darwin":
return concurrent.futures.ThreadPoolExecutor()
return concurrent.futures.ProcessPoolExecutor()

def main(stdin, stdout):
with concurrent.futures.ProcessPoolExecutor() as executor:
with create_main_executor() as executor:
for parse_request in stdin:
parse_request = json.loads(parse_request)
repo_root = parse_request["repo_root"]
Expand Down