Naihong Tang | 23 Nov 09:10 2010
Picon

run long time command in urwid

Hello,


I plan to write a RAID building program with urwid. In the first window, input some parameters, after user press the OK button, popup a new window with progress bar, indicating the finished percentage, and do not accept user input in this window, this window will close itself after building procedure finished. Since the RAID building procedure will last long time, about 10 hours, so it cannot be placed in OnButtonPressed() event. After reading the urwid document, I think use thread or subclass widget Run() can do this. I would like to know if there is other simple way to implement. 

Thanks! 


Naihong
_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 23 Nov 18:19 2010

Re: run long time command in urwid

Naihong Tang wrote on 2010-11-23 03:10:
> Hello,
> 
> I plan to write a RAID building program with urwid. In the first window,
> input some parameters, after user press the OK button, popup a new
> window with progress bar, indicating the finished percentage, and do not
> accept user input in this window, this window will close itself after
> building procedure finished. Since the RAID building procedure will last
> long time, about 10 hours, so it cannot be placed in OnButtonPressed()
> event. After reading the urwid document, I think use thread or subclass
> widget Run() can do this. I would like to know if there is other simple
> way to implement. 

You could use threads, but it might be easier to just poll the status of
the RAID array creation from a MainLoop.set_alarm_in callback.  That way
it's easy to update what's displayed (no synchronization required)

http://excess.org/urwid/reference.html#MainLoop

I'm not sure where you're reading about Run or OnButtonPressed methods,
though..

HTH
Ian
Naihong Tang | 23 Nov 23:27 2010
Picon

Re: run long time command in urwid

Thank you, Ian.


OnButtonPressed is Button's on_press callback, Run is MainLoop's run() method, sorry for inaccurate expression.
The RAID building including a sequence of commands. Some commands are synchronized, I mean the command will run until the operation finished. Other commands are unsynchronized, after send the command, it will finish immediately,  polling is needed to get the status and result. I have already done this part with pexpect module. Now I want to integrate it with urwid, so the user can adjust some system parameters at beginning. Seems start a thread will be the right choice.
I have another question, can the working thread call urwid to update the GUI interface, or only the main thread can do it.

Regards

Naihong

On Tue, Nov 23, 2010 at 9:19 AM, Ian Ward <ian <at> excess.org> wrote:
Naihong Tang wrote on 2010-11-23 03:10:
> Hello,
>
> I plan to write a RAID building program with urwid. In the first window,
> input some parameters, after user press the OK button, popup a new
> window with progress bar, indicating the finished percentage, and do not
> accept user input in this window, this window will close itself after
> building procedure finished. Since the RAID building procedure will last
> long time, about 10 hours, so it cannot be placed in OnButtonPressed()
> event. After reading the urwid document, I think use thread or subclass
> widget Run() can do this. I would like to know if there is other simple
> way to implement.

You could use threads, but it might be easier to just poll the status of
the RAID array creation from a MainLoop.set_alarm_in callback.  That way
it's easy to update what's displayed (no synchronization required)

http://excess.org/urwid/reference.html#MainLoop

I'm not sure where you're reading about Run or OnButtonPressed methods,
though..

HTH
Ian

_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid

_______________________________________________
Urwid mailing list
Urwid <at> lists.excess.org
http://lists.excess.org/mailman/listinfo/urwid
Ian Ward | 24 Nov 02:38 2010

Re: run long time command in urwid

Naihong Tang wrote on 2010-11-23 17:27:
> Thank you, Ian.
> 
> OnButtonPressed is Button's on_press callback, Run is MainLoop's run()
> method, sorry for inaccurate expression.
> The RAID building including a sequence of commands. Some commands are
> synchronized, I mean the command will run until the operation finished.
> Other commands are unsynchronized, after send the command, it will
> finish immediately,  polling is needed to get the status and result. I
> have already done this part with pexpect module. Now I want to integrate
> it with urwid, so the user can adjust some system parameters at
> beginning. Seems start a thread will be the right choice.
> I have another question, can the working thread call urwid to update the
> GUI interface, or only the main thread can do it.

You should only use the main thread to update the UI, or both threads
might try to update it simultaneously with poor results.

The solution is to use a pipe that you write to from in the worker
thread (or process) and pass the read end to
loop.event_loop.watch_file() in the main thread (or process).  The
function you pass to watch_file will be called any time the pipe is
readable, so you empty the pipe, update your UI and call loop.draw_screen()

This question comes up enough that I should write a good example to
point people to.  I'll post to the list when that happens.

Ian

Gmane