Process#poll

Question.

Situation:
I want to start a process, then loop, checking for its status, so that I
can “know” when it finishes, and not block the Tk.mainloop.

Anybody know how to determine runningness of a process in ruby?
Thanks!

Roger P. wrote:

Question.

Situation:
I want to start a process, then loop, checking for its status, so that I
can “know” when it finishes, and not block the Tk.mainloop.

Anybody know how to determine runningness of a process in ruby?
Thanks!

Don’t the Process.wait family of methods do what you want? Maybe:

Process.waitpid(pid, Process::WNOHANG)

I could possibly add something like this to Rev, although you would only
be
able to receive the events when you’re running a Rev event loop, and MRI
may
swallow SIGCHLD.

Joel VanderWerf wrote:

Roger P. wrote:

Question.

Situation:
I want to start a process, then loop, checking for its status, so that I
can “know” when it finishes, and not block the Tk.mainloop.

Anybody know how to determine runningness of a process in ruby?
Thanks!

Don’t the Process.wait family of methods do what you want? Maybe:

Process.waitpid(pid, Process::WNOHANG)

Interesting. I think that that’s what Python’s Process#poll uses
internally. Unfortunately it appears that both it and Process::WNOHANG
and Linux only (I’m on doze). Hmm.
-r

Roger P. wrote:

Don’t the Process.wait family of methods do what you want? Maybe:

Process.waitpid(pid, Process::WNOHANG)

Interesting. I think that that’s what Python’s Process#poll uses
internally. Unfortunately it appears that both it and Process::WNOHANG
and Linux only (I’m on doze). Hmm.
-r

The win32-process gem claims to handle some of that functionality…

Roger P. wrote:

Works for me :slight_smile:
-r

If you’re going to fire up a thread (as in Timeout), you could also do
something like this (maybe a bit more efficient):

done = false
Thread.new {Process.wait(a.pid); done = true}
loop do

if done
# …
end
end

(I hope that doesn’t fail on windows, but didn’t test it…)

The win32-process gem claims to handle some of that functionality…

It probably does give some hints as to how one could accomplish this
[not waiting for INFINITY, for example].
http://allgems.ruby-forum.com/gems/doc/win32-process/0.6.0

I did figure out a way that appears to work in windows, for any
followers…

http://betterlogic.com/roger/?p=1900

Works for me :slight_smile:
-r

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs