# How to balance between GUI and Speed?

**URL:** <https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914>\
**Category:** wxRuby\
**Created:** [May 13, 2011, 5:24am UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914 "2011-05-13T05:24:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [May 13, 2011, 5:24am UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/1 "2011-05-13T05:24:59Z")

</div>

Hi everyone,

I’m using WxRuby to develop a GUI app, and it needs to transfer files  
through ftp.  
If I use ftp.put\_binary method, the GUI can response, but the ftp is  
very slow.  
And if I use Process.create and Process.waitpid to call windows ftp,  
it’s much faster, but the GUI doesn’t respond at all until the ftp is  
finished.

Please tell me if there’s other way to do ftp in a GUI app, with a high  
ftp speed and responsable GUI.

Thanks.

---

<div class="post-metadata">

**Author:** ![fofo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fofo](https://www.ruby-forum.com/u/fofo)\
**Post date:** [May 15, 2011, 5:03pm UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/2 "2011-05-15T17:03:08Z")

</div>

hi

On 13/05/11 04:24, Fengfeng Li wrote:

> I’m using WxRuby to develop a GUI app, and it needs to transfer files  
> through ftp.  
> If I use ftp.put\_binary method, the GUI can response, but the ftp is  
> very slow.  
> And if I use Process.create and Process.waitpid to call windows ftp,  
> it’s much faster, but the GUI doesn’t respond at all until the ftp is  
> finished.
> 
> Please tell me if there’s other way to do ftp in a GUI app, with a high  
> ftp speed and responsable GUI.

Can’t help with the speed of Ruby’s FTP library, but in general if you  
want to keep the GUI responsive whilst doing some long-running task,  
there are a few ways:

evt\_idle (straightforward, useful if the task can be broken down into  
bits)  
threads (more complex, but more flexible)

You will probably need to use the latter. There are a lot of wxruby  
discussions on using threads - have a search through the archives for  
further info and examples, and also have a look in the samples directory  
included with wxruby.

alex

---

<div class="post-metadata">

**Author:** ![fofo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fofo](https://www.ruby-forum.com/u/fofo)\
**Post date:** [May 20, 2011, 6:10am UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/3 "2011-05-20T06:10:53Z")

</div>

Hi,

Thanks for you reply. My problem is:

For example, I created 4 threads, one of them is for wxruby GUI, and the  
other three will do similar things as below. Then I found that, When  
call\_external in one thread is processing, the GUI thread(wonn’t  
response) and the other two threads(wonn’t do step2) will wait(because I  
use Process.waitpid?)

But I hope only the caller thread wait for call\_external to end, the  
other threads just continue there own behavior.

#---------------------------------------  
for i in 1…3 do  
Thread.new{  
call\_external(xxx to use system ftp)  
…do step2  
}  
end  
#---------------------------------------  
def call\_external(cmd)  
pid = Process.create( :app\_name =\> cmd,  
:startup\_info =\>  
{:sw\_flags =\> Process::SW\_HIDE ,  
:startf\_flags =\>  
Process::STARTF\_USESHOWWINDOW}  
).process\_id  
Process.waitpid(pid)  
end  
#---------------------------------------

I’ve looked into the win32-process lib, and found there’s no method to  
check if a process is finished, so I must use waitpid. But the waitpid  
stop all the other threads, which’re unacceptable for me.

Is there any other way?

Thanks.

---

<div class="post-metadata">

**Author:** ![fofo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fofo](https://www.ruby-forum.com/u/fofo)\
**Post date:** [May 20, 2011, 10:48am UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/4 "2011-05-20T10:48:13Z")

</div>

On 20/05/2011 05:10, Fengfeng Li wrote:

> For example, I created 4 threads, one of them is for wxruby GUI, and the  
> other three will do similar things as below. Then I found that, When  
> call\_external in one thread is processing, the GUI thread(wonn’t  
> response) and the other two threads(wonn’t do step2) will wait(because I  
> use Process.waitpid?)

Mario’s response is more general, but also I wonder if something like  
curb ([http://curb.rubyforge.org/](http://curb.rubyforge.org/)), ruby bindings for libcurl, might help  
in your case? It has call-backs for progress of downloads.

alex

---

<div class="post-metadata">

**Author:** ![fofo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fofo](https://www.ruby-forum.com/u/fofo)\
**Post date:** [October 27, 2011, 4:44am UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/5 "2011-10-27T04:44:58Z")

</div>

Hi,

Mario S. wrote in post #999797:

> Hello Fengfeng,
> 
> I actually ran into similar issues that your running into. Which  
> prompted  
> me to create this library: [http://repos.ruby-im.net/xprocess/](http://repos.ruby-im.net/xprocess/) It will  
> allow  
> you to execute processes, as well as capture output, and send input to  
> the  
> sub-process, without blocking any of the Ruby Threads. The interface to  
> the  
> library is pretty simple. I don’t have any docs for the library, but in  
> simplistic terms of an example:
> 
> my\_proc = XProcess.new(cmd)  
> my\_proc.execute(my\_args)  
> while my\_proc.exists? do  
> Thread.pass() # Allow other threads to do their work while this  
> process  
> is working.  
> end
> 
> # Process has ended, we can parse output of my\_proc through
> 
> my\_proc.out.read\_lines(), or various other IO methods.
> 
> hth,
> 
> Mario

I ran setup.rb and some errors occured as below:

—\> lib  
—\> lib/XProcess  
\<— lib/XProcess  
\<— lib  
—\> ext  
—\> ext/XProcess  
—\> ext/XProcess/io\_peek  
C:/ruby/bin/ruby.exe  
D:/xprocess-79fffe13d20a/ext/XProcess/io\_peek/extconf.rb  
checking for ruby.h… no  
\*\*\* D:/xprocess-79fffe13d20a/ext/XProcess/io\_peek/extconf.rb failed \*\*\*  
Could not create Makefile due to some reason, probably lack of  
necessary libraries and/or headers. Check the mkmf.log file for more  
details. You may need configuration options.

Provided configuration options:  
–with-opt-dir  
–without-opt-dir  
–with-opt-include  
–without-opt-include=${opt-dir}/include  
–with-opt-lib  
–without-opt-lib=${opt-dir}/lib  
–with-make-prog  
–without-make-prog  
–srcdir=D:/xprocess-79fffe13d20a/ext/XProcess/io\_peek  
–curdir  
–ruby=C:/ruby/bin/ruby  
–with-.-dir  
–without-.-dir  
–with-.-include  
–without-.-include=${.-dir}/include  
–with-.-lib  
–without-.-lib=${.-dir}/lib  
setup.rb:655:in `command': system("C:/ruby/bin/ruby.exe" "D:/xprocess-79fffe13d20a/ext/XProcess/io_peek/extconf.rb") failed (RuntimeError) from setup.rb:660:in `ruby’  
from setup.rb:1238:in `extconf' from setup.rb:1230:in `config\_dir\_ext’  
from setup.rb:1532:in ` __send__' from setup.rb:1532:in `traverse’  
from setup.rb:1549:in `dive_into' from setup.rb:1530:in `traverse’  
from setup.rb:1534:in `traverse' from setup.rb:1533:in `each’  
from setup.rb:1533:in `traverse' from setup.rb:1549:in `dive\_into’  
from setup.rb:1530:in `traverse' from setup.rb:1534:in `traverse’  
from setup.rb:1533:in `each' from setup.rb:1533:in `traverse’  
from setup.rb:1549:in `dive_into' from setup.rb:1530:in `traverse’  
from setup.rb:1524:in `exec_task_traverse' from setup.rb:1519:in `each’  
from setup.rb:1519:in `exec_task_traverse' from setup.rb:1223:in `exec\_config’  
from setup.rb:991:in `exec_config' from setup.rb:812:in `invoke’  
from setup.rb:773:in `invoke’  
from setup.rb:1578

My enviroment is: Windows XP 32-BIT, ruby 1.8.7 (2011-02-18 patchlevel  
334) [i386-mingw32].  
Could you have a look at these? thank you.

---

<div class="post-metadata">

**Author:** ![fofo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fofo](https://www.ruby-forum.com/u/fofo)\
**Post date:** [May 20, 2011, 8:11am UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/6 "2011-05-20T08:11:59Z")

</div>

Hello Fengfeng,

I actually ran into similar issues that your running into. Which  
prompted  
me to create this library: [http://repos.ruby-im.net/xprocess/](http://repos.ruby-im.net/xprocess/) It will  
allow  
you to execute processes, as well as capture output, and send input to  
the  
sub-process, without blocking any of the Ruby Threads. The interface to  
the  
library is pretty simple. I don’t have any docs for the library, but in  
simplistic terms of an example:

my\_proc = XProcess.new(cmd)  
my\_proc.execute(my\_args)  
while my\_proc.exists? do  
Thread.pass() # Allow other threads to do their work while this  
process  
is working.  
end

# Process has ended, we can parse output of my\_proc through

my\_proc.out.read\_lines(), or various other IO methods.

hth,

Mario

---

<div class="post-metadata">

**Author:** ![fofo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/5e9695/32.png) [@fofo](https://www.ruby-forum.com/u/fofo)\
**Post date:** [October 27, 2011, 12:14pm UTC](https://www.ruby-forum.com/t/how-to-balance-between-gui-and-speed/206914/7 "2011-10-27T12:14:08Z")

</div>

Hello Fengfeng,

The error your getting, is from the fact that extconf.rb can’t find  
ruby.h.  
And given that your running from Windows XP, I’m guessing that your  
running  
the One Click Installer for it. You will however, need the Development  
Environment for the One Click Installer, in order to build the XProcess  
and  
various extensions used in making it work. The Development Environment  
can  
be found here:  
[http://rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z](http://rubyforge.org/frs/download.php/66888/devkit-3.4.5r3-20091110.7z)  
You  
will need a utility such as WinRar or 7zip to extract the files.

hth,

Mario

On Wed, Oct 26, 2011 at 10:44 PM, Fengfeng Li [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > the  
> > is working.  
> > —\> lib  
> > Could not create Makefile due to some reason, probably lack of  
> > –with-make-prog  
> > setup.rb:655:in `command': system("C:/ruby/bin/ruby.exe" from setup.rb:1533:in `each’  
> > from setup.rb:1519:in `exec\_task\_traverse’  
> > –  
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> wxruby-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/wxruby-users](http://rubyforge.org/mailman/listinfo/wxruby-users)

–  
Mario S.  
Captain 3rd  
CO - Geo 99  
CO - USS T’hy’la  
XO - Diplomatic Corps - Second Life  
[http://www.iftcommand.com/chapters/thyla/](http://www.iftcommand.com/chapters/thyla/)

> **[HOME | The Federation](https://www.trekfederation.com)**

[http://geo99.ruby-im.net](http://geo99.ruby-im.net)
