Process#poll

R

Roger Pack

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!
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

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

Joel VanderWerf

Roger said:
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)
 
R

Roger Pack

Joel said:
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
 
J

Joel VanderWerf

Roger said:
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...
 
J

Joel VanderWerf

Roger said:
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 :)
-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...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,169
Messages
2,570,919
Members
47,459
Latest member
Vida00R129

Latest Threads

Top