Skip to content

Commit

Permalink
Faster load_module with threading
Browse files Browse the repository at this point in the history
  • Loading branch information
onuratakan committed May 24, 2024
1 parent f5d7d7c commit d25e2dd
Showing 1 changed file with 37 additions and 18 deletions.
55 changes: 37 additions & 18 deletions upsonic/remote/on_prem.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ def load_module(self, module_name, version=None):
sub_module_name = module_name.replace(".", "_")
module_name = sub_module_name

the_threads = []


the_all_imports = {}
for i in the_all:
original_i = i
Expand Down Expand Up @@ -467,25 +470,41 @@ def load_module(self, module_name, version=None):
except:
if self.tester:
traceback.print_exc()
def gather():
if version != None:
version_list_response = self.get_version_history(original_i)
version_list = []
for each_v in version_list_response:
version_list.append(each_v.replace(original_i+":", ""))


if version in version_list:
try:
the_all_imports[i] = self.get(
original_i,
version,
pass_python_version_control=True
)
except:
the_all_imports[i] = self.get(original_i, pass_python_version_control=True)
else:
the_all_imports[i] = self.get(original_i, pass_python_version_control=True)

if version != None:
version_list_response = self.get_version_history(original_i)
version_list = []
for each_v in version_list_response:
version_list.append(each_v.replace(original_i+":", ""))


if version in version_list:
try:
the_all_imports[i] = self.get(
original_i,
version,
pass_python_version_control=True
)
except:
the_all_imports[i] = self.get(original_i, pass_python_version_control=True)
else:
the_all_imports[i] = self.get(original_i, pass_python_version_control=True)
while len(the_threads) >= self.thread_number:
for each in the_threads:
if not each.is_alive():
the_threads.remove(each)
time.sleep(0.1)

the_thread = threading.Thread(target=gather)
the_thread.start()
the_threads.append(the_thread)


for each in the_threads:
each.join()



import types

Expand Down

0 comments on commit d25e2dd

Please sign in to comment.