A
A
Artem Gapchenko2012-05-18 17:22:46
Python
Artem Gapchenko, 2012-05-18 17:22:46

Parallel execution of threads in PySide?

Hello.
For my term paper, I am writing an application that, roughly speaking, should calculate each next state of the cellular automaton and display it on the screen from time to time. I decided to parallelize the calculations - I created my own MyThread class, inherited it from QRunnable. I created an array of two objects of the MyThread class and from time to time I launch them for execution in this way:

for w in self.__workers:
    QtCore.QThreadPool.globalInstance().start(w)
QtCore.QThreadPool.globalInstance().waitForDone()

I looked at the task manager, and saw that as one core was occupied by a task, so it remained one. I thought that this might be due to the number of threads in the pool, I decided to increase their number to three (one thread is the main thread, the other two are MyThreads).
QtCore.QThreadPool.globalInstance().setMaxThreadCount(3)

No change.
I'm doing something wrong somewhere, but I can't figure out what and where. Maybe someone faced the task of writing an application on PySide, which had to run on at least two cores? Any ideas what I'm doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
mik_os, 2012-05-18
@artemgapchenko

Python uses the GIL ( link ). In simple words: only 1 piece of python code is executing at any given time. To load all cores use multiprocessing .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question