Skip to content

Commit

Permalink
Bug Fix: Plugins Fail To Load on Python 3.8+ (#505)
Browse files Browse the repository at this point in the history
* Set fork multiprocessing as the upgrade to python 3.8 switched to spawn processing which does not share memory between child processes.

* Pass settings object into child processes. Create the baseline json only once

Co-authored-by: John-Paul Dakran <dakranj@c02g1288md6q.phub.net.cable.rogers.com>
  • Loading branch information
jpdakran and John-Paul Dakran authored Feb 2, 2022
1 parent 73ffbc3 commit d0df05a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion detect_secrets/core/secrets_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

from . import scan
from .potential_secret import PotentialSecret
from detect_secrets.settings import configure_settings_from_baseline
from detect_secrets.settings import get_settings


class PatchedFile:
Expand Down Expand Up @@ -55,7 +57,13 @@ def scan_files(self, *filenames: str, num_processors: Optional[int] = None) -> N
if not num_processors:
num_processors = mp.cpu_count()

with mp.Pool(processes=num_processors) as p:
child_process_settings = get_settings().json()

with mp.Pool(
processes=num_processors,
initializer=configure_settings_from_baseline,
initargs=(child_process_settings,),
) as p:
for secrets in p.imap_unordered(
_scan_file_and_serialize,
[os.path.join(self.root, filename) for filename in filenames],
Expand Down

0 comments on commit d0df05a

Please sign in to comment.