from multiprocessing import cpu_count, Process from shutil import copy from com.abc.lib.series import get_fibo_series # print(cpu_count()) def copying_job(path, destination): # user defined thread # IO operation (less of CPU) copy(path, destination) print('Copying done') path = '/Users/mehulchopra/Documents/personal/training/ivan-python-core/math_ops.py' destination = '/Users/mehulchopra/Desktop' udp = Process(target=copying_job, args=(path, destination)) udp.start() # CPU operation n = 1000 print(get_fibo_series(n)) udp.join( ) # ensures that the subprocess is destroyed once its work is done and is not lingering
from pathlib import Path from shutil import copy from com.abc.lib.series import get_fibo_series input_path = input('Enter the full file path from where u want to copy : ') output_dir = input('Enter the full dir path to which you want to copy : ') p1 = Path(input_path) p2 = Path(output_dir) if not p1.exists(): print('Please enter the right input path') else: input_name = p1.name if p2.exists() and p2.is_dir(): output_file_path = '{0}/{1}'.format(output_dir, input_name) # single threaded fashion # sequential execution copy(input_path, output_file_path) # IO operation # 10 MB file or more # CPU is free (idle) print('Copying done!') n = 30 print(get_fibo_series(n)) # CPU operation else: print('Please enter right output dir path')