select blocked?

kafa6226 at my-deja.com kafa6226 at my-deja.com
Mon Nov 20 03:18:10 EST 2000


Hi,All!
	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"
		sys.exit(1)
	if pid == 0:	# child process
		os.execvp('telnet', ('telnet','localhost',))

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

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

if __name__ == '__main__': main()
---------------------------


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list