Added a command-line option to control the number of workers.
This commit is contained in:
parent
4f5867adae
commit
44949c6cf9
3 changed files with 31 additions and 14 deletions
|
|
@ -22,6 +22,8 @@
|
||||||
│Options: │
|
│Options: │
|
||||||
│ -h --help Show this screen and exit. │
|
│ -h --help Show this screen and exit. │
|
||||||
│ -n --no-sandbox Don't prevent changes to the filesystem. │
|
│ -n --no-sandbox Don't prevent changes to the filesystem. │
|
||||||
|
│ -w COUNT --workers=COUNT The number of processes working in parallel. │
|
||||||
|
│ By default it is twice the number of cpus. │
|
||||||
│ │
|
│ │
|
||||||
│Keys: │
|
│Keys: │
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0mh[0m[38;2;255;255;255m[48;2;0;0;0m - Show the help screen. (toggle) │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0mh[0m[38;2;255;255;255m[48;2;0;0;0m - Show the help screen. (toggle) │
|
||||||
|
|
@ -33,7 +35,7 @@
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0mn[0m[38;2;255;255;255m[48;2;0;0;0m - Move to the next issue. │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0mn[0m[38;2;255;255;255m[48;2;0;0;0m - Move to the next issue. │
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0mN[0m[38;2;255;255;255m[48;2;0;0;0m - Move to the next issue of the current tool. │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0mN[0m[38;2;255;255;255m[48;2;0;0;0m - Move to the next issue of the current tool. │
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0mo[0m[38;2;255;255;255m[48;2;0;0;0m - Order files by type, or by directory location. (toggle) │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0mo[0m[38;2;255;255;255m[48;2;0;0;0m - Order files by type, or by directory location. (toggle) │
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0mp[0m[38;2;255;255;255m[48;2;0;0;0m - Pause work. (toggle) │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0mp[0m[38;2;255;255;255m[48;2;0;0;0m - Pause workers. (toggle) │
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0ms[0m[38;2;255;255;255m[48;2;0;0;0m - Change the appearance of result statuses. (toggle) │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0ms[0m[38;2;255;255;255m[48;2;0;0;0m - Change the appearance of result statuses. (toggle) │
|
||||||
│ [0m[38;2;0;255;0m[48;2;0;0;0mq[0m[38;2;255;255;255m[48;2;0;0;0m - Quit. │
|
│ [0m[38;2;0;255;0m[48;2;0;0;0mq[0m[38;2;255;255;255m[48;2;0;0;0m - Quit. │
|
||||||
│ │
|
│ │
|
||||||
|
|
@ -55,6 +57,4 @@
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
│ │
|
||||||
│ │
|
|
||||||
│ │
|
|
||||||
└──────────────────────────────────────────────────────────────────────────────────────────────────┘[0m
|
└──────────────────────────────────────────────────────────────────────────────────────────────────┘[0m
|
||||||
28
vigil
28
vigil
|
|
@ -28,6 +28,8 @@ Example:
|
||||||
Options:
|
Options:
|
||||||
-h --help Show this screen and exit.
|
-h --help Show this screen and exit.
|
||||||
-n --no-sandbox Don't prevent changes to the filesystem.
|
-n --no-sandbox Don't prevent changes to the filesystem.
|
||||||
|
-w COUNT --workers=COUNT The number of processes working in parallel.
|
||||||
|
By default it is twice the number of cpus.
|
||||||
|
|
||||||
Keys:
|
Keys:
|
||||||
*h - Show the help screen. (toggle)
|
*h - Show the help screen. (toggle)
|
||||||
|
|
@ -961,7 +963,8 @@ def update_screen(main_widget, appearance_changed_event):
|
||||||
fill3.patch_screen(main_widget)
|
fill3.patch_screen(main_widget)
|
||||||
|
|
||||||
|
|
||||||
def main(root_path, is_sandboxed=True, is_being_tested=False):
|
def main(root_path, worker_count=multiprocessing.cpu_count()*2,
|
||||||
|
is_sandboxed=True, is_being_tested=False):
|
||||||
global _UPDATE_THREAD_STOPPED
|
global _UPDATE_THREAD_STOPPED
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
jobs_added_event = threading.Event()
|
jobs_added_event = threading.Event()
|
||||||
|
|
@ -1009,10 +1012,9 @@ def main(root_path, is_sandboxed=True, is_being_tested=False):
|
||||||
else:
|
else:
|
||||||
log.log_message("Running without the filesystem sandbox...")
|
log.log_message("Running without the filesystem sandbox...")
|
||||||
log.log_message("Starting workers...")
|
log.log_message("Starting workers...")
|
||||||
worker_total = multiprocessing.cpu_count() * 2
|
for index in range(worker_count):
|
||||||
for index in range(worker_total):
|
|
||||||
runners.append(Runner(sandbox, screen._is_paused, is_being_tested))
|
runners.append(Runner(sandbox, screen._is_paused, is_being_tested))
|
||||||
log.log_message("Workers started. (%s)" % worker_total)
|
log.log_message("Workers started. (%s)" % worker_count)
|
||||||
for runner in runners:
|
for runner in runners:
|
||||||
args = (summary, log, jobs_added_event, appearance_changed_event)
|
args = (summary, log, jobs_added_event, appearance_changed_event)
|
||||||
threading.Thread(target=runner.job_runner, args=args,
|
threading.Thread(target=runner.job_runner, args=args,
|
||||||
|
|
@ -1084,8 +1086,17 @@ def manage_cache(root_path):
|
||||||
open(timestamp_path, "w").close()
|
open(timestamp_path, "w").close()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
def process_arguments():
|
||||||
arguments = docopt.docopt(__doc__.replace("*", ""), help=False)
|
arguments = docopt.docopt(__doc__.replace("*", ""), help=False)
|
||||||
|
try:
|
||||||
|
worker_count = (int(arguments["--workers"]) if arguments["--workers"]
|
||||||
|
is not None else multiprocessing.cpu_count() * 2)
|
||||||
|
except ValueError:
|
||||||
|
print("Please supply a number for --workers.")
|
||||||
|
sys.exit(1)
|
||||||
|
if worker_count == 0:
|
||||||
|
print("There must be at least one worker.")
|
||||||
|
sys.exit(1)
|
||||||
show_help = arguments["--help"]
|
show_help = arguments["--help"]
|
||||||
if show_help:
|
if show_help:
|
||||||
print(_get_help_text())
|
print(_get_help_text())
|
||||||
|
|
@ -1098,10 +1109,15 @@ if __name__ == "__main__":
|
||||||
print("File is not a directory:", root_path)
|
print("File is not a directory:", root_path)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
is_sandboxed = not arguments["--no-sandbox"]
|
is_sandboxed = not arguments["--no-sandbox"]
|
||||||
|
return root_path, worker_count, is_sandboxed
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
root_path, worker_count, is_sandboxed = process_arguments()
|
||||||
if is_sandboxed:
|
if is_sandboxed:
|
||||||
subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy"
|
subprocess.call(["sudo", "-p", "Vigil needs sudo to create the filesy"
|
||||||
"stem sandbox... [sudo] password for %u: ", "true"])
|
"stem sandbox... [sudo] password for %u: ", "true"])
|
||||||
with terminal.console_title("vigil: " + os.path.basename(root_path)):
|
with terminal.console_title("vigil: " + os.path.basename(root_path)):
|
||||||
manage_cache(root_path)
|
manage_cache(root_path)
|
||||||
with chdir(root_path): # FIX: Don't change directory if possible.
|
with chdir(root_path): # FIX: Don't change directory if possible.
|
||||||
main(root_path, is_sandboxed)
|
main(root_path, worker_count, is_sandboxed)
|
||||||
|
|
|
||||||
|
|
@ -250,7 +250,8 @@ class MainTestCase(unittest.TestCase):
|
||||||
vigil.manage_cache(root_path)
|
vigil.manage_cache(root_path)
|
||||||
with vigil.chdir(root_path):
|
with vigil.chdir(root_path):
|
||||||
with contextlib.redirect_stdout(io.StringIO()):
|
with contextlib.redirect_stdout(io.StringIO()):
|
||||||
vigil.main(root_path, is_being_tested=True)
|
vigil.main(root_path, worker_count=2, is_sandboxed=True,
|
||||||
|
is_being_tested=True)
|
||||||
for file_name in ["summary.pickle", "creation_time", "log",
|
for file_name in ["summary.pickle", "creation_time", "log",
|
||||||
"foo-metadata", "foo-contents"]:
|
"foo-metadata", "foo-contents"]:
|
||||||
self.assertTrue(os.path.exists(".vigil/" + file_name))
|
self.assertTrue(os.path.exists(".vigil/" + file_name))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue