Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiprocessing not working #1

Open
Puneet-Singh1996 opened this issue Jun 1, 2018 · 1 comment
Open

Multiprocessing not working #1

Puneet-Singh1996 opened this issue Jun 1, 2018 · 1 comment

Comments

@Puneet-Singh1996
Copy link

 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)

Below picture shows that CPU was using only 1 core instead 2 were there.
capture

@kute
Copy link
Owner

kute commented Jul 9, 2018

May be your recover_data.size is less than multiprocessing.cpu_count().

image

image

multiprocessing.cpu_count() is 8 in my own, when the size of get_data_from_mysql() return is less than 8, it depends on your data'size for your process

@kute kute closed this as completed Jul 9, 2018
@kute kute reopened this Jul 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants