James,<br><br>Yes. Only one thread ACTUALLY executes on at any time on a uniprocessor system. That is logical.<br><br>But the thing is.. I am not at all wanting to speed up anything .. :P :P<br><br>I am wanting to solve an issue, which in the present case seems possible ONLY by using two threads.<br>
<br>My intention is to somehow have GUI updates in a synchronous manner, and not rely upon "gobject.idle_add", which would have to have dividing a long workflow into many sub-parts, and chaining these sub-parts through "gobject.idle_add".<br>
This is EXTREMELY painful, especially when one needs to do it on an already existing codebase.<br><br><br>So, the two-thread workflow would make that easier. And yes, only one thread will execute any time; in fact, my suggested workflow takes advantage of this only-one-thread-running fact :D<br>
<br><br>At the same time, I also think that there is no easy way to do what I want. At least not without hacking onto the python-core code (event loop implementation).<br><br><br>Thanks and Regards,<br>Ajay<br><br><div class="gmail_quote">
On Tue, Aug 21, 2012 at 12:02 PM, James Cameron <span dir="ltr"><<a href="mailto:quozl@laptop.org" target="_blank">quozl@laptop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
First, learn that on a single processor system, only one thread<br>
actually executes at a given time, so if you think you have more than<br>
one thread of execution, you're wrong and you really only have one.<br>
<br>
As soon as you expand the time for sampling, yes, more than one<br>
thread, or process, may execute.<br>
<br>
In this situation, threads are an abstraction which distorts reality.<br>
<div class="im"><br>
On Tue, Aug 21, 2012 at 11:33:55AM +0530, Ajay Garg wrote:<br>
> Thanks James for the reply.<br>
><br>
><br>
> On Tue, Aug 21, 2012 at 3:47 AM, James Cameron <<a href="mailto:quozl@laptop.org">quozl@laptop.org</a>> wrote:<br>
><br>
> On Tue, Aug 21, 2012 at 12:11:13AM +0530, Ajay Garg wrote:<br>
> > So, is there a way to have the code always in-order; in other words,<br>
> > have the GUI updates absolutely synchronous?<br>
><br>
> No, not without waiting for the update to complete, and if you do<br>
> this, the code runs very slowly.<br>
><br>
> (When there is only one CPU, only one process can execute on it at a<br>
> time. The updates are placed in a pipeline to the display, and the<br>
> display process runs them as soon as it is practical to do so. If<br>
> your process does not release the CPU, then your process will likely<br>
> continue executing until it hits something that will cause it to<br>
> release. It is better to be specific and use idle_add to release.)<br>
><br>
><br>
> Right.<br>
><br>
> Now, from what I believe, that there is just one "main" thread, that is<br>
> responsible for running the "normal, backend" code, and the same "main" thread<br>
> does the GUI updates (of the events present in the display pipeline), when it<br>
> has nothing more to do with the "normal, backend" code.<br>
><br>
> This also means, that doing something like<br>
><br>
> main_thread.wait()<br>
><br>
> would be idiotic, as that would stall the GUI updates as well.<br>
<br>
</div>I don't understand what you would hope to achieve by calling .wait().<br>
<div class="im"><br>
> So, does there exist a method, that could cause doing the GUI updates in a<br>
> different (other than the "main" thread) ?<br>
> If yes, that would solve the issue, as the following would then be feasible ::<br>
><br>
> <main thread> logic statement 1<br>
> <main thread> spawn a new thread, and pass the GUI-update event to<br>
> it |<br>
> <main thread> "joins" on the new<br>
> thread |<br>
><br>
> | anywhere in this interval, the new thread performs the GUI update<br>
><br>
> |<br>
><br>
> |<br>
><br>
> new thread terminates<br>
> <main thread> logic statement 2<br>
><br>
><br>
><br>
> At first, it seems that the "<main thread> spawn a new thread, and pass the<br>
> GUI-update event to it" step is trivial.<br>
> However, the thing to note that in a default python configuration, all GUI<br>
> update events are scheduled in the context of the main thread.<br>
><br>
> So, only if the GUI update events could be scheduled to be processed in a<br>
> custom thread - that would be awesome !!!<br>
><br>
><br>
> Please let me know if any such method exists :)<br>
<br>
</div>No, I don't think so. It is an event loop implementation only.<br>
<br>
For more information, google "Threads Considered Harmful", and check<br>
out John Ousterhout's paper "Why Threads Are A Bad Idea (for most<br>
purposes)."<br>
<div class="HOEnZb"><div class="h5"><br>
--<br>
James Cameron<br>
<a href="http://quozl.linux.org.au/" target="_blank">http://quozl.linux.org.au/</a><br>
</div></div></blockquote></div><br>