Skip to content

Commit

Permalink
process: give better error message on Process.close
Browse files Browse the repository at this point in the history
  • Loading branch information
saghul committed Aug 31, 2014
1 parent 94b0a42 commit 12b7718
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/process.c
Expand Up @@ -489,6 +489,18 @@ Process_func_kill(Process *self, PyObject *args)
}


static PyObject *
Process_func_close(Process *self, PyObject *args)
{
if (!((Handle*)self)->initialized) {
PyErr_SetString(PyExc_RuntimeError, "Object was not initialized, spawn was not called.");
return NULL;
}

return Handle_func_close((Handle *) self, args);
}


static PyObject *
Process_pid_get(Process *self, void *closure)
{
Expand Down Expand Up @@ -580,6 +592,7 @@ static PyMethodDef
Process_tp_methods[] = {
{ "spawn", (PyCFunction)Process_func_spawn, METH_VARARGS|METH_KEYWORDS, "Spawn the child process." },
{ "kill", (PyCFunction)Process_func_kill, METH_VARARGS, "Kill this process with the specified signal number." },
{ "close", (PyCFunction)Process_func_close, METH_VARARGS, "Close process handle." },
{ "disable_stdio_inheritance", (PyCFunction)Process_func_disable_stdio_inheritance, METH_NOARGS|METH_CLASS, "Disables inheritance for file descriptors / handles that this process inherited from its parent." },
{ NULL }
};
Expand Down
4 changes: 4 additions & 0 deletions tests/test_process.py
Expand Up @@ -31,6 +31,10 @@ def proc_exit_cb(proc, exit_status, term_signal):
self.assertEqual(self.close_cb_called, 1)
self.assertNotEqual(pid, None)

def test_process_close(self):
proc = pyuv.Process(self.loop)
self.assertRaises(RuntimeError, proc.close)

def test_process_noargs(self):
self.exit_cb_called = 0
self.close_cb_called = 0
Expand Down

0 comments on commit 12b7718

Please sign in to comment.