Reputation: 1383
I want to get data from stdin and pass it over to a server. And vice versa: get data from the server and display in the terminal. Of course I don't want to block neither the stdin nor the socket. Here is a piece of code:
while True:
inputready = select.select([server_socket, sys.stdin], [], [], self.timeout)[0]
for src in inputready:
...
Is it possible to figure the type of src here?
Are there any other ways, you can think of, to solve the problem?
Upvotes: 2
Views: 1914
Reputation: 182754
Are there any other ways, you can think of, to solve the problem?
You could just check:
for src in inputready:
if src == server_socket:
...
Now back to your first question, you could:
os.fstat
to get a stat bufferstat.S_ISSOCK
to check if it's a socketAgain, there's little reason to do this.
Upvotes: 7