Question

So I wrote the following piece of code:

Shoes.app(:title=> "Humax Uploader", :width=>400, :height=>400) {
    background rgb(240, 250, 208)
    stack(margin:10) {
        title "Humax Uploader"
        server = '[ip]'
        user = '[user]'
        pass = '[pass]'
        require 'net/ftp'
        @feedback = para "Find a file:"
        flow do
            @filename = edit_line :width => 150
            para ' '
            button 'Browse...' do
                @filename.text = ask_open_file
            end
        end

        file_list = ['My Music','My Photo','My Video']
        list_box :items => file_list do |list|
                Net::FTP.open(server, user, pass) { |ftp|
                    usize = 0
                    fsize = File.size(@filename.text)
                    ftp.putbinaryfile(@filename.text,"/mnt/hd2/" + list.text + "/" + File.basename(@filename.text),1024) { |block|  
                        usize += block.size
                        @p.fraction = fsize/usize
                    }
                    @file_select.text = "File uploaded!"
                    ftp.close
                }
            end
        @p = progress :width => 360
        @file_select = para " "
    }
}

Basically, what it does is allowing a user to select a file, the folder it should go into and then, the program should upload it.

This happens correctly: Stuff uploads fine, but unfortunately: The program window hangs during upload. Why is this happening (do you experience the same problems?) and how can I fix it?

Thanks for your help!

Note that I am running this script on Windows and have not yet 'build' to executable yet.

Was it helpful?

Solution

Does it hang forever or just until the file has been uploaded? In either case I think this is a scheduling problem.

You might want to consider running the upload in a separate thread (this link might also be of use) or perhaps running it as a separate process and using some sort of socket or file for inter-process communication.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top