Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errno::ECHILD thrown from Process.waitpid, some Process methods #732

Merged
merged 8 commits into from May 27, 2013
1 change: 1 addition & 0 deletions lib-topaz/bootstrap.rb
Expand Up @@ -11,6 +11,7 @@
load_bootstrap.call("comparable.rb")
load_bootstrap.call("enumerable.rb")
load_bootstrap.call("enumerator.rb")
load_bootstrap.call("errno.rb")
load_bootstrap.call("file.rb")
load_bootstrap.call("fixnum.rb")
load_bootstrap.call("hash.rb")
Expand Down
4 changes: 4 additions & 0 deletions lib-topaz/errno.rb
@@ -0,0 +1,4 @@
module Errno
class ECHILD < Exception
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inherits SystemCallError as far as I can tell.

end
end
1 change: 0 additions & 1 deletion spec/tags/core/process/wait_tags.txt
@@ -1,4 +1,3 @@
fails:Process.wait raises a Errno::ECHILD if there are no child processes
fails:Process.wait waits for any child process if no pid is given
fails:Process.wait waits for a specific child if a pid is given
fails:Process.wait coerces the pid to an Integer
Expand Down
26 changes: 17 additions & 9 deletions topaz/modules/process.py
Expand Up @@ -4,6 +4,8 @@

from topaz.module import ModuleDef
from topaz.system import IS_WINDOWS
from topaz.objects.classobject import W_ClassObject
from topaz.objects.moduleobject import W_ModuleObject


if IS_WINDOWS:
Expand Down Expand Up @@ -35,15 +37,21 @@ def method_pid(self, space):

@moduledef.function("waitpid", pid="int")
def method_waitpid(self, space, pid=-1):
pid, status = os.waitpid(pid, 0)
status = WEXITSTATUS(status)
w_status = space.send(
space.find_const(self, "Status"),
"new",
[space.newint(pid), space.newint(status)]
)
space.globals.set(space, "$?", w_status)
return space.newint(pid)
try:
pid, status = os.waitpid(pid, 0)
status = WEXITSTATUS(status)
w_status = space.send(
space.find_const(self, "Status"),
"new",
[space.newint(pid), space.newint(status)]
)
space.globals.set(space, "$?", w_status)
return space.newint(pid)
except OSError as ex:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only the minim amount of code should be inside of the try block.

errno = space.find_const(self, "Errno")
echild = space.find_const(errno, "ECHILD")
assert isinstance(echild, W_ClassObject)
raise space.error(echild, str(ex))

@moduledef.function("exit", status="int")
def method_exit(self, space, status=0):
Expand Down