[Gambas-user] how to make threats

Sebastian Kulesz sebikul at ...626...
Wed Nov 13 21:20:18 CET 2013


I had the same problem, you can look at my solution here [0]. Basically, i
used a pool of HttpClients with the async property set to True.

The logic goes like this. I have an index files which tracks around 120
files stored online. Not going to get into how i update each file without
downloading the rest, but suppose i want to download all files to build a
local copy. By default, i create an array of 10 HttpClient instances. With
DEFAULT_CLIENT_COUNT you can set it to be more.
I then load each URL into a queue and start a timer which runs every 10 ms.
In each run, the timer checks for a free HttpClient instance, if there is
one it loads it with the popped  URL and saves the file into a predefined
folder with the same name as it was stored in the server. It runs until the
queue count is 0.

You could use tasks, but i found this to be better as it is easier to keep
track of the progress.



[0]
http://bazaar.launchpad.net/~sebikul/mundus/trunk/view/head:/.src/Index.module


On Wed, Nov 13, 2013 at 5:05 PM, PICCORO McKAY Lenz
<mckaygerhard at ...626...>wrote:

> Tobias respond me this in another topic:
>
> From: Tobias Boege <taboege at ...626...>
> > Subject: Re: [Gambas-user] wait vs sleep confusion, console works,
> >
> > Ahh. Actually, there is no "main thread" or something. Gambas is single-
> > threaded throughout. In GUI programs, the so-called "event loop" kicks in
> > automatically because you have windows open. See the docs[0].
>
> That its a bad notice for me.. i think about simulate that multithread
> by making separate projects and call each then complied as EXECT AS
> PROCESS etc etc.. this can work as expected? but i dont know how to
> manage multiple projects inside one in the ide!
>
> > You can also
> > force the event loop to run by putting
> >
> > While True
> >   Wait 2 ^ 30
> > Wend
> >
> yeah that's basic men, but my program its a daemon that must
> downloading several files parallel, so with this loop only acepts one
> event per loop (either if i use wget as process and manage such)
>
> > BTW: Gambas is a nice language. You cannot make threats with it :-)
> yeah i like very much gambas, not for easy, DUE ITS NOT PORTED TO GUINDOWS!
>
> > Threads are also not possible in Gambas currently. (You should look up
> the word
> > "threat" in a dictionary.) The closest thing you can have is "Task" but
> > I've
> > no experience with this.
>
> where i find examples about taks in gambas?
>
> >
> > Regards,
> > Tobi
> >
>
> --
> Lenz McKAY Gerardo (PICCORO)
> http://qgqlochekone.blogspot.com
>
>
> ------------------------------------------------------------------------------
> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
> Free app hosting. Or install the open source package on any LAMP server.
> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>



More information about the User mailing list