multithreading - How to prevent the threading module from slowing down your programs performance in Python? -


when click button on tkinter, python program, button freeze , wouldn't able else on program. actual command button still work, functionality of entire program went away. combat issue, implemented threading, in turn fixed problem. after implemented threading, performance of program slowed way down.

does know causes this? , how can fix it?

edit----------------------------------------edit

this tried when using multiprocessing module opposed threading module.

from multiprocessing import process  def initplaylist(self):   #code here def playplaylist(self):   p = process(target = initplaylist)   p.start()   p.join() 

it's hard without seeing code, reason performance hit global interpreter lock, or gil. python interpreter isn't thread-safe, uses gil protect bugs , crashes caused concurrency issues. lock allows single thread execute python instructions time, means don't true parallelism across cpu cores way can in other, gil-less languages. effectively, 1 thread executes bit, gets suspended, thread can start, gets suspended, etc. still concurrency, not true parallelism.

the common way fix use multiprocessing module, instead of threading. multiprocessing utilizes processes concurrency instead of threads, thereby avoiding limitations of gil. has drawbacks, though, since it's more difficult , more overhead share state between processes threads.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -