[Python-Dev] Re: PEP 324 (process module)
Peter Astrand
astrand at lysator.liu.se
Tue Aug 3 20:09:29 CEST 2004
> Last time I tried it there were still a few windows issues (docs say
> these have been resolved), but I thought the API was well-designed.
The details: The module works great on Windows currently, but requires the
win32all extensions. The idea is to get rid of this dependency by writing
a glue module, pretty much as _winreg.
Work on such a _process module has been done on two fronts:
* A friendly Python-developer has gotten quite far, but was experiencing
some strange hangs. I haven't been able to look at this work yet.
* I've started working on an implementation myself. I was using _winreg as
some sort of template. The problem is: I've never written extension
modules before :-) It was quite easy to export the numeric constants, but
when I came to creating Python objects, I was lost. I'll guess I need to
read some documentation.
This is what remains:
win32api:
GetStdHandle
GetCurrentProcess, DuplicateHandle
win32pipe:
CreatePipe
win32process:
CreateProcess, STARTUPINFO, GetExitCodeProcess
win32event:
WaitForSingleObject
Here's the module so far:
/*
_process.c
*/
#include "windows.h"
#include "Python.h"
#include "structmember.h"
#include "malloc.h" /* for alloca */
/* The win32api module reports the function name that failed,
but this concept is not in the Python core.
Hopefully it will one day, and in the meantime I dont
want to lose this info...
*/
#define PyErr_SetFromWindowsErrWithFunction(rc, fnname) \
PyErr_SetFromWindowsErr(rc)
/* Forward declares */
/* Doc strings */
// FIXME
PyDoc_STRVAR(module_doc,
"This module provides...\n");
static struct PyMethodDef process_methods[] = {
NULL,
};
static void
insint(PyObject * d, char * name, long value)
{
PyObject *v = PyInt_FromLong(value);
if (!v || PyDict_SetItemString(d, name, v))
PyErr_Clear();
Py_XDECREF(v);
}
#define ADD_INT(val) insint(d, #val, val)
PyMODINIT_FUNC init_process(void)
{
PyObject *m, *d;
m = Py_InitModule3("_process", process_methods, module_doc);
d = PyModule_GetDict(m);
Py_INCREF(PyExc_WindowsError);
if (PyDict_SetItemString(d, "error",
PyExc_WindowsError) != 0)
return;
/* Add the relevant constants */
ADD_INT(DUPLICATE_SAME_ACCESS);
ADD_INT(STARTF_USESTDHANDLES);
ADD_INT(STD_INPUT_HANDLE);
ADD_INT(STD_OUTPUT_HANDLE);
ADD_INT(STD_ERROR_HANDLE);
ADD_INT(INFINITE);
ADD_INT(WAIT_OBJECT_0);
}
(I will be away for a couple of days.)
/Peter Åstrand <astrand at lysator.liu.se>
More information about the Python-Dev
mailing list