Skip to content

Commit

Permalink
Multiprocessing lib supports context manager protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
pchakraborty committed Apr 16, 2024
1 parent ce62590 commit 376baf2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/mepo/command/restore-state.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys
import time
import multiprocessing as mp
import atexit

from ..state import MepoState
from ..git import GitRepository
Expand All @@ -11,9 +10,8 @@
def run(args):
print('Checking status...'); sys.stdout.flush()
allcomps = MepoState.read_state()
pool = mp.Pool()
atexit.register(pool.close)
result = pool.map(check_component_status, allcomps)
with mp.Pool() as pool:
result = pool.map(check_component_status, allcomps)
restore_state(allcomps, result)

def check_component_status(comp):
Expand All @@ -27,5 +25,11 @@ def restore_state(allcomps, result):
current_version = result[index][0].split(' ')[1]
orig_version = comp.version.name
if current_version != orig_version:
print(colors.YELLOW + "Restoring " + colors.RESET + "{} to {} from {}.".format(comp.name, colors.GREEN + orig_version + colors.RESET, colors.RED + current_version + colors.RESET))
print(colors.YELLOW
+ "Restoring "
+ colors.RESET
+ "{} to {} from {}.".format(
comp.name,
colors.GREEN + orig_version + colors.RESET,
colors.RED + current_version + colors.RESET))
git.checkout(comp.version.name)

0 comments on commit 376baf2

Please sign in to comment.