[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

thread question

Joe Van Dyk

4/25/2005 4:12:00 PM

Every second, a function in the class that's being made available via
DRb should be called automatically. How would I do that?

So I'd have

class Server
def update
# stuff gets updated
end
end

server = DRb.start_service....

server.update() # <== somehow ran every second

DRb.thread.join



6 Answers

Brian Schröder

4/25/2005 4:22:00 PM

0

On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> Every second, a function in the class that's being made available via
> DRb should be called automatically. How would I do that?
>
> So I'd have
>
> class Server
> def update
> # stuff gets updated
> end
> end
>
> server = DRb.start_service....
>
> server.update() # <== somehow ran every second

How about:

update_thread = Thread.new(server) do | s |
loop do
sleep 1
s.update
end
end


>
> DRb.thread.join
>
>

or is there anything special with drb that prohibits this?

best regards,

Brian

--
http://ruby.brian-sch...

multilingual _non rails_ ruby based vocabulary trainer:
http://www.vocabu... | http://www.g... | http://www.vok...



Joe Van Dyk

4/25/2005 4:45:00 PM

0

On 4/25/05, Brian Schröder <ruby.brian@gmail.com> wrote:
> On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > Every second, a function in the class that's being made available via
> > DRb should be called automatically. How would I do that?
> >
> > So I'd have
> >
> > class Server
> > def update
> > # stuff gets updated
> > end
> > end
> >
> > server = DRb.start_service....
> >
> > server.update() # <== somehow ran every second
>
> How about:
>
> update_thread = Thread.new(server) do | s |
> loop do
> sleep 1
> s.update
> end
> end
>
> >
> > DRb.thread.join
> >
> >
>
> or is there anything special with drb that prohibits this?
>

I wasn't sure about how the interactions between the threads would
work. I'll try the above and see how it works.



Brian Schröder

4/25/2005 5:08:00 PM

0

On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> On 4/25/05, Brian Schröder <ruby.brian@gmail.com> wrote:
> > On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > > Every second, a function in the class that's being made available via
> > > DRb should be called automatically. How would I do that?
> > >
> > > So I'd have
> > >
> > > class Server
> > > def update
> > > # stuff gets updated
> > > end
> > > end
> > >
> > > server = DRb.start_service....
> > >
> > > server.update() # <== somehow ran every second
> >
> > How about:
> >
> > update_thread = Thread.new(server) do | s |
> > loop do
> > sleep 1
> > s.update
> > end
> > end
> >
> > >
> > > DRb.thread.join
> > >
> > >
> >
> > or is there anything special with drb that prohibits this?
> >
>
> I wasn't sure about how the interactions between the threads would
> work. I'll try the above and see how it works.
>
>

One difference from your whish is, that this calls the function with a
sleeptime of approximately one second, or sometimes more, and not
every second. Calling it every second is more difficult.

Also, if I remember correctly, ruby threads may be blocked for some
time by some large io activities.

hope to help,

Brian

--
http://ruby.brian-sch...

multilingual _non rails_ ruby based vocabulary trainer:
http://www.vocabu... | http://www.g... | http://www.vok...



Robert Klemme

4/25/2005 5:12:00 PM

0


"Brian Schröder" <ruby.brian@gmail.com> schrieb im Newsbeitrag
news:7993c66305042510075b914ce7@mail.gmail.com...
> On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
>> On 4/25/05, Brian Schröder <ruby.brian@gmail.com> wrote:
>> > On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
>> > > Every second, a function in the class that's being made available via
>> > > DRb should be called automatically. How would I do that?
>> > >
>> > > So I'd have
>> > >
>> > > class Server
>> > > def update
>> > > # stuff gets updated
>> > > end
>> > > end
>> > >
>> > > server = DRb.start_service....
>> > >
>> > > server.update() # <== somehow ran every second
>> >
>> > How about:
>> >
>> > update_thread = Thread.new(server) do | s |
>> > loop do
>> > sleep 1
>> > s.update
>> > end
>> > end
>> >
>> > >
>> > > DRb.thread.join
>> > >
>> > >
>> >
>> > or is there anything special with drb that prohibits this?
>> >
>>
>> I wasn't sure about how the interactions between the threads would
>> work. I'll try the above and see how it works.
>>
>>
>
> One difference from your whish is, that this calls the function with a
> sleeptime of approximately one second, or sometimes more, and not
> every second. Calling it every second is more difficult.
>
> Also, if I remember correctly, ruby threads may be blocked for some
> time by some large io activities.
>
> hope to help,

Another issue worth mentioning is proper synchronization. But since we
don't know anything about the nature of the classes and tasks we could only
speculate. Just in case the OP needs it: have a look at Mutex and Monitor.

Kind regards

robert

Joe Van Dyk

4/25/2005 5:27:00 PM

0

On 4/25/05, Robert Klemme <bob.news@gmx.net> wrote:
>
> "Brian Schröder" <ruby.brian@gmail.com> schrieb im Newsbeitrag
> news:7993c66305042510075b914ce7@mail.gmail.com...
> > On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> >> On 4/25/05, Brian Schröder <ruby.brian@gmail.com> wrote:
> >> > On 25/04/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> >> > > Every second, a function in the class that's being made available via
> >> > > DRb should be called automatically. How would I do that?
> >> > >
> >> > > So I'd have
> >> > >
> >> > > class Server
> >> > > def update
> >> > > # stuff gets updated
> >> > > end
> >> > > end
> >> > >
> >> > > server = DRb.start_service....
> >> > >
> >> > > server.update() # <== somehow ran every second
> >> >
> >> > How about:
> >> >
> >> > update_thread = Thread.new(server) do | s |
> >> > loop do
> >> > sleep 1
> >> > s.update
> >> > end
> >> > end
> >> >
> >> > >
> >> > > DRb.thread.join
> >> > >
> >> > >
> >> >
> >> > or is there anything special with drb that prohibits this?
> >> >
> >>
> >> I wasn't sure about how the interactions between the threads would
> >> work. I'll try the above and see how it works.
> >>
> >>
> >
> > One difference from your whish is, that this calls the function with a
> > sleeptime of approximately one second, or sometimes more, and not
> > every second. Calling it every second is more difficult.

That's not an issue. It seems to work great. Thanks!

> >
> > Also, if I remember correctly, ruby threads may be blocked for some
> > time by some large io activities.
> >
> > hope to help,
>
> Another issue worth mentioning is proper synchronization. But since we
> don't know anything about the nature of the classes and tasks we could only
> speculate. Just in case the OP needs it: have a look at Mutex and Monitor.
>

Syncing's also not an issue. But I'll keep that in mind. Thanks.



Ben Turner

5/18/2007 12:40:00 PM

0

David Hartung wrote:

>
> If true, this is very serious.
>
> Bush should have understood that it will be years before the Iraqis are
> ready to govern themselves, and even then, Iraq could wind up being two or
> more countries. The USA should have understood before we even went in,
> that we would have to plan on governing Iraq for at least 50 years, while
> teaching the Iraqis the concept of "rule of law".



Now this is funny. How could the US teach any nation about the rule of law?
This administration has ignored or ripped up any law that got in the way of
policy.

Victims of this rogue administration:

1. Constitutional law
2. Federal law
3. International law
4. Treaty law