[paramiko] Using select() to determine when channel write buffer not full
Dwayne Litzenberger
dwayne at oscl.ca
Tue Nov 13 06:28:29 PST 2007
Hi there!
When working with a native socket, if I want to check if a send() would not
block, I can do something like this:
(rr, ww, ee) = select.select([], [sock], [], 0)
That obviously doesn't work with Paramiko channels, since (from what I can
tell) the file descriptor returned by Channel.fileno() isn't actually used
for I/O.
Imagine that I want to copy data coming in at high speed over a socket to a
much slower Paramiko channel. What I would like to do is something like
this, but it doesn't seem to be possible:
writeBuf = ""
while loop:
if writeBuf != "":
channel.set_notify_on_writable(True)
else:
channel.set_notify_on_writable(False)
rr = [abort_fd, channel, sock]
if len(writeBuf) >= 8192:
# Don't allow writeBuf to grow infinitely
rr.remove(sock)
(rr, ww, ee) = select.select(rr, [], [], 0)
if abort_fd in rr:
# Another thread has requested that we abort
break
if sock in rr:
# Data is ready to be read from the socket
writeBuf += sock.recv(8192)
if channel in rr:
if channel.recv_ready():
# do stuff
if channel.recv_stderr_ready():
# do stuff
if channel.send_ready():
count = channel.send(writeBuf)
writeBuf = writeBuf[count:]
# ...
Is anything similar possible?
--
Dwayne Litzenberger, B.A.Sc.
Information Technology Analyst
Open Systems Canada Limited
1627 Broad Street
Regina, SK S4P1X3
Office: 306.359.6725
http://www.oscl.ca/
More information about the paramiko
mailing list