I have use all types of multiprocessing Pool but still the program only using single core (available=8).Any help will be appreciated and thanks in advance.
import multiprocessing from multiprocessing import Pool class pdf_gen(): def __init__(self): pdf = self.pdf = FPDF() pdf.set_auto_page_break(True,0.1) def get_data_from_mysql(self) : pdf = self.pdf # connection is established and result is stored in 'res'. dup = [] dup.insert(0,res) z = tuple(dup) pool = multiprocessing.Pool(multiprocessing.cpu_count()) pool.apply_async(self.mysql_to_pdf_data,z) pool.close() pool.join() def mysql_to_pdf_data(self,*result) : try : pdf = self.pdf # Entered data need to be in pdf finally : pdf.output('save_pdf.pdf','F') It takes approximately 20 mins to make pdf but I need it to take upto max 4 minutes.
I have updated my code.
import multiprocessing from multiprocessing import Pool class pdf_gen(): def __init__(self): pdf = self.pdf = FPDF() pdf.set_auto_page_break(True,0.1) def get_data_from_mysql(self) : pdf = self.pdf # connection is established and result is stored in 'res'. dup = [] dup.insert(0,res) z = tuple(dup) return z def mysql_to_pdf_data(self,*result) : try : pdf = self.pdf # Entered data need to be in pdf finally : pdf.output('save_pdf.pdf','F') def main() : pdf = pdf_gen() recover_data = pdf.get_data_from_mysql() pool = multiprocessing.Pool(multiprocessing.cpu_count()) pool.map(pdf.mysql_to_pdf_data,recover_data) I have attached the cpu utilisaion it using only 1 core at a particular time
