Merge multiprocess

This commit is contained in:
Dimitris Zlatanidis 2024-03-22 13:10:22 +02:00
parent 1e3d1f242d
commit b66ca72fed
2 changed files with 8 additions and 30 deletions

View file

@ -3,7 +3,7 @@
import os
from pathlib import Path
from multiprocessing import Process
from multiprocessing import Process, Queue
from urllib3.exceptions import HTTPError
from urllib3 import PoolManager, ProxyManager, make_headers
@ -36,14 +36,14 @@ class CheckUpdates(Configs):
self.option_for_repository: bool = self.utils.is_option(
('-o', '--repository='), flags)
def check_the_repositories(self) -> dict:
def check_the_repositories(self, queue) -> None:
if self.option_for_repository:
self.repositories(self.repository)
else:
self.check_updates_for_repositories()
self.view_messages(self.compare)
return self.compare
queue.put(self.compare)
def check_updates_for_repositories(self) -> None:
for repo, enable in self.repos.repositories.items():
@ -125,11 +125,12 @@ class CheckUpdates(Configs):
else:
print(f'\n\n{self.endc}{self.yellow}No updated packages since the last check.{self.endc}')
def updates(self) -> None:
def updates(self) -> dict:
queue = Queue()
message: str = 'Checking for news, please wait...'
# Starting multiprocessing
process_1 = Process(target=self.check_the_repositories)
process_1 = Process(target=self.check_the_repositories, args=(queue,))
process_2 = Process(target=self.progress.progress_bar, args=(message,))
process_1.start()
@ -144,3 +145,4 @@ class CheckUpdates(Configs):
# Restore the terminal cursor
print('\x1b[?25h', self.endc)
return queue.get()

View file

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
from pathlib import Path
from multiprocessing import Process, Queue
from slpkg.configs import Configs
from slpkg.views.views import View
@ -606,29 +605,6 @@ class UpdateRepositories(Configs):
self.data.install_sbo_data()
def check_for_updates(self, queue) -> dict:
compare: dict = self.check_updates.check_the_repositories()
return queue.put(compare)
def repositories(self) -> None:
queue = Queue()
message: str = 'Checking for news, please wait...'
# Starting multiprocessing
process_1 = Process(target=self.check_for_updates, args=(queue,))
process_2 = Process(target=self.progress.progress_bar, args=(message,))
process_1.start()
process_2.start()
# Wait until process 1 finish
process_1.join()
# Terminate process 2 if process 1 finished
if not process_1.is_alive():
process_2.terminate()
# Restore the terminal cursor
print('\x1b[?25h', self.endc, end='')
self.repos_for_update: dict = queue.get()
self.repos_for_update: dict = self.check_updates.updates()
self.update_the_repositories()