Print ps (process status) for us when starting a new thread.

Even less shuffling of stdout (only at start of new interpreter).

Interact properly with new interpreter initialization conventions
(must use Py_Initialize/Py_Finalize *and*
Py_NewInterpreter/Py_EndInterpreter).

Probably more minor changes.
diff --git a/Demo/pysvr/pysvr.c b/Demo/pysvr/pysvr.c
index c70863f..c651648 100644
--- a/Demo/pysvr/pysvr.c
+++ b/Demo/pysvr/pysvr.c
@@ -48,9 +48,12 @@
 static void *service_thread(struct workorder *);
 static void run_interpreter(FILE *, FILE *);
 static int run_command(char *, PyObject *);
+static void ps(void);
 
 static char *progname = "pysvr";
 
+static PyThreadState *gtstate;
+
 main(int argc, char **argv)
 {
 	int port = PORT;
@@ -98,7 +101,7 @@
 static void
 main_thread(int port)
 {
-	int sock, conn, size;
+	int sock, conn, size, i;
 	struct sockaddr_in addr, clientaddr;
 
 	sock = socket(PF_INET, SOCK_STREAM, 0);
@@ -108,7 +111,7 @@
 		exit(1);
 	}
 
-	memset(&addr, '\0', sizeof addr);
+	memset((char *)&addr, '\0', sizeof addr);
 	addr.sin_family = AF_INET;
 	addr.sin_port = htons(port);
 	addr.sin_addr.s_addr = 0L;
@@ -126,8 +129,9 @@
 
 	fprintf(stderr, "Listening on port %d...\n", port);
 
-	for (;;) {
+	for (i = 0; ; i++) {
 		size = sizeof clientaddr;
+		memset((char *) &clientaddr, '\0', size);
 		conn = accept(sock, (struct sockaddr *) &clientaddr, &size);
 		if (conn < 0) {
 			oprogname();
@@ -136,6 +140,7 @@
 		}
 
 		size = sizeof addr;
+		memset((char *) &addr, '\0', size);
 		if (getsockname(conn, (struct sockaddr *)&addr, &size) < 0) {
 			oprogname();
 			perror("can't get socket name of connection");
@@ -150,8 +155,21 @@
 			close(conn);
 			continue;
 		}
+		if (i == 4) {
+			close(conn);
+			break;
+		}
 		create_thread(conn, &clientaddr);
 	}
+
+	close(sock);
+
+	if (gtstate) {
+		PyEval_AcquireThread(gtstate);
+		gtstate = NULL;
+		Py_Finalize();
+	}
+	exit(0);
 }
 
 static void
@@ -192,8 +210,11 @@
 static void
 init_python()
 {
-	PyEval_InitThreads(); /* Create and acquire the interpreter lock */
-	PyEval_ReleaseLock(); /* Release the lock */
+	if (gtstate)
+		return;
+	Py_Initialize(); /* Initialize the interpreter */
+	PyEval_InitThreads(); /* Create (and acquire) the interpreter lock */
+	gtstate = PyEval_SaveThread(); /* Release the thread state */
 }
 
 static void *
@@ -203,6 +224,8 @@
 
 	fprintf(stderr, "Start thread for connection %d.\n", work->conn);
 
+	ps();
+
 	input = fdopen(work->conn, "r");
 	if (input == NULL) {
 		oprogname();
@@ -264,6 +287,10 @@
 	new_stdin = PyFile_FromFile(input, "<socket-in>", "r", NULL);
 	new_stdout = PyFile_FromFile(output, "<socket-out>", "w", NULL);
 
+	PySys_SetObject("stdin", new_stdin);
+	PySys_SetObject("stdout", new_stdout);
+	PySys_SetObject("stderr", new_stdout);
+
 	for (n = 1; !PyErr_Occurred(); n++) {
 		Py_BEGIN_ALLOW_THREADS
 		fprintf(output, "%d> ", n);
@@ -286,10 +313,6 @@
 		if (p[0] == '#' || p[0] == '\0')
 			continue;
 
-		PySys_SetObject("stdin", new_stdin);
-		PySys_SetObject("stdout", new_stdout);
-		PySys_SetObject("stderr", new_stdout);
-
 		end = run_command(buffer, globals);
 		if (end < 0)
 			PyErr_Print();
@@ -327,3 +350,11 @@
 	Py_DECREF(v);
 	return 0;
 }
+
+static void
+ps()
+{
+	char buffer[100];
+	sprintf(buffer, "ps -l -p %d </dev/null | tail +2l\n", getpid());
+	system(buffer);
+}