select blocked?

kafa6226 at kafa6226 at
Mon Nov 20 09:18:10 CET 2000

	I am a newbie to python and try to write a middle layer
between the telnet and rxvt to provide some special analyse function. I
use the select module to listen on the stdin and pty-master-end which
connected with the telnet. but the select statement seems blocked when
the string passed from telnet not ended with a NewLine character. I
have searched the archive but chould not find the answer, can you give
me a help? thanks!
	The source is attached.
#!/usr/bin/env python

import sys
import os
import pty
import select

def main():

	(pid, fd) = pty.fork()

	if pid == -1:
		print "Couldn't fork"
	if pid == 0:	# child process
		os.execvp('telnet', ('telnet','localhost',))

	# parent process
 	while 1:
		delay = 1
        	(r,w,e) = [sys.stdin.fileno(), fd], [], [],
		for File in r:
			if File == sys.stdin.fileno():
				#from_user =
				#from_user = sys.stdin.raw_input()
				from_user = 0, 1024)
				print "user input:"+from_user
				if from_user == "q": break
				#os.write( fd, from_user )

			if File == fd:
				from_telnet =, 1024)
				sys.stdout.write( from_telnet )

if __name__ == '__main__': main()

Sent via
Before you buy.

More information about the Python-list mailing list