franz steinhaeusler wrote:
>
> 1) in C#, often one uses thread.sleep() in loops, (I don't know, if
> that is ok anyway), to give mainthread and thread time.
That is NOT a common practice in quality code, even in C#. The
operating systems are FAR better at managing CPU assignments than your
application will ever be. Your applications should just use the time
they need, and let the system manage the balancing.
> Is there any necessity to prevent cpu overusage in python?
No, just like there is no need to do so in C#. You have an incorrect
mental model.
> Is there a difference in thread handling in python and wxPython?
The issues are the same as what you face in C#. All GUI manipulation
must be done in the main thread. With C#, you use Invoke and
InvokeRequired to switch to the main thread for GUI stuff. With
wxPython, you send messages, or use wx.CallAfter when you need to tweak
the UI.
> 2) actual case:
>
> Threadstatt
> [code]
> here I post a command event, which should show a custom dialog
> and her I want to wait in the thread, until the custom dialog is left
> by ok or cancel button.
> [code]
> Threadend
>
> What thread events/locks (or how), ... should I use to wait for the
> dialog is finished?
James gave you excellent advice here. When you're working with an
event-driven systems (as all modern UI frameworks are), you have to
start thinking in terms of events. If you have a thread that needs to
wait for a UI event, then you need to think about splitting the task
into two parts.
Triggering event:
Start thread part 1
Thread 1
Compute
Compute
Send event to main thread and exit
Event handler
Display dialog
Dialog OK event:
Start thread part 2
Thread part 2
Compute
Compute
Notice how there is never anything just spinning in a wasteful loop.
The two parts of the thread could be one function with a parameter, or
you could have a state variable that tells you how far you have progressed.
--
Tim Roberts,
ti...@probo.com
Providenza & Boekelheide, Inc.