How to balance between GUI and Speed?

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.

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

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.

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/), ruby bindings for libcurl, might help
in your case? It has call-backs for progress of downloads.

alex

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/ 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.

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/ 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

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
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 [email protected]
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/.


wxruby-users mailing list
[email protected]
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://geo99.ruby-im.net