MCPcopy Index your code
hub / github.com/nodejs/node / ParallelState

Class ParallelState

tools/gyp/pylib/gyp/input.py:559–603  ·  view source on GitHub ↗

Class to keep track of state when processing input files in parallel. If build files are loaded in parallel, use this to keep track of state during farming out and processing parallel jobs. It's stored in a global so that the callback function can have access to it.

Source from the content-addressed store, hash-verified

557
558
559class ParallelState:
560 """Class to keep track of state when processing input files in parallel.
561
562 If build files are loaded in parallel, use this to keep track of
563 state during farming out and processing parallel jobs. It's stored
564 in a global so that the callback function can have access to it.
565 """
566
567 def __init__(self):
568 # The multiprocessing pool.
569 self.pool = None
570 # The condition variable used to protect this object and notify
571 # the main loop when there might be more data to process.
572 self.condition = None
573 # The "data" dict that was passed to LoadTargetBuildFileParallel
574 self.data = None
575 # The number of parallel calls outstanding; decremented when a response
576 # was received.
577 self.pending = 0
578 # The set of all build files that have been scheduled, so we don't
579 # schedule the same one twice.
580 self.scheduled = set()
581 # A list of dependency build file paths that haven't been scheduled yet.
582 self.dependencies = []
583 # Flag to indicate if there was an error in a child process.
584 self.error = False
585
586 def LoadTargetBuildFileCallback(self, result):
587 """Handle the results of running LoadTargetBuildFile in another process."""
588 self.condition.acquire()
589 if not result:
590 self.error = True
591 self.condition.notify()
592 self.condition.release()
593 return
594 (build_file_path0, build_file_data0, dependencies0) = result
595 self.data[build_file_path0] = build_file_data0
596 self.data["target_build_files"].add(build_file_path0)
597 for new_dependency in dependencies0:
598 if new_dependency not in self.scheduled:
599 self.scheduled.add(new_dependency)
600 self.dependencies.append(new_dependency)
601 self.pending -= 1
602 self.condition.notify()
603 self.condition.release()
604
605
606def LoadTargetBuildFilesParallel(

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…