QThread (occasionally) won't start
-
I have a class which inherits QThread, and I always new a object of that class and call the start() method when initialize my program.
Then I use a python script to star/stop my program over and over, for thousands of times.
Occasionally, the QThread won't start. Actually, only for once, out of about 3000 times, the QThread failed to launch.What's the possible reason? And how do I make sure QThread is started?(since start() is a void function)
-
Hard to say without having code details. However I will digg into some run-time conditions, e.g., opening files or memory consumption that could cause your thread-creation-cycle to fail on some iterations.
Now, knowing that your thread is started also depends on what you are doing. I would use the "started":http://doc.qt.nokia.com/latest/qthread.html#started signal to get informed that the thread is started, and maybe I will log to a log file such event.
-
You could ask QThread for the state:
"isRunning":http://doc.qt.nokia.com/4.7/qthread.html#isRunning
-
Indeed, I can use QThread's started signal or isRunning() method, but that won't explain why if a thread isn't launched.
-
So, I don'i know why it happens in your special case, but sometimes you can hit OS bounds. Perhaps, there are too many threads running in paralell
-
[quote author="leonidwang" date="1319448574"]Indeed, I can use QThread's started signal or isRunning() method, but that won't explain why if a thread isn't launched.[/quote]
If you are not able to see which threads are started, how can you discriminate which are not started? The idea was to get info to understand what threads are running so to get the conditions under which the other are not started.
-
I just put some logs in that thread, and my script collects those logs, that's how I know it is not launched.
I give up finding out the "reason", anyhow, it is a low-probability event. I'm now querying the thread status and restart it if it is not running.
[quote author="fluca1978" date="1319456844"]
[quote author="leonidwang" date="1319448574"]Indeed, I can use QThread's started signal or isRunning() method, but that won't explain why if a thread isn't launched.[/quote]If you are not able to see which threads are started, how can you discriminate which are not started? The idea was to get info to understand what threads are running so to get the conditions under which the other are not started.[/quote]
-
Ok, you find a solution that is fine for you aim(s).
The only doubt I have is about the low-probability event: may be this probability raises when deployed to another architecture? Just think about it. -
[quote author="fluca1978" date="1319528580"]Ok, you find a solution that is fine for you aim(s).
The only doubt I have is about the low-probability event: may be this probability raises when deployed to another architecture? Just think about it.[/quote]But that's some problem out of Qt's scope.
-
[quote author="leonidwang" date="1319600202"]
But that's some problem out of Qt's scope.
[/quote]Of course, but it is in the scope of your application. I was just suggesting you to investigate more...