From 12b77188fa8b3936804f86c4c1188a1b66a9ad34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Sun, 31 Aug 2014 13:56:05 +0200 Subject: [PATCH] process: give better error message on Process.close --- src/process.c | 13 +++++++++++++ tests/test_process.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/src/process.c b/src/process.c index 4589a415..8f1aa57c 100644 --- a/src/process.c +++ b/src/process.c @@ -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) { @@ -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 } }; diff --git a/tests/test_process.py b/tests/test_process.py index 357a7c44..d28cf420 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -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