473,698 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

paramiko and stackless

I've written a port forwarding wrapper with paramiko for an app we use
and it works fine except that it consumes way too much processor.
(i.e. 25% +) I'm trying to write a stackless-based server class to
replace the threading one but I can't get the tunnel the wrapper
creates to work for more than one instance of the app. I based my
code on the example HTTP server on the stackless site. Relevant code
follows. The glovia variable is the result of subprocess.Pope n().

<pre>
class ForwardServer (SocketServer.T CPServer):
allow_reuse_add ress = True
def __init__(self, *args, **kwargs):
SocketServer.TC PServer.__init_ _(self, *args, **kwargs)
self.socket.set blocking(0)

def serve_forever(s elf, glovia):
while glovia.poll() is None:
verbose("Handle request")
self.handle_req uest()

def handle_request( self):
try:
request, client_address = self.get_reques t()
except socket.error:
return
verbose("Adding handler tasklet")
stackless.taskl et(self.handle_ request_tasklet )(request,
client_address)

def handle_request_ tasklet(self, request, client_address) :
if self.verify_req uest(request, client_address) :
try:
self.process_re quest(request, client_address)
except:
self.handle_err or(request, client_address)
self.close_requ est(request)
class Handler (SocketServer.B aseRequestHandl er):
def handle(self):
verbose("Enteri ng Handler.handle" )
peername = self.request.ge tpeername()
try:
chan = self.ssh_transp ort.open_channe l('direct-tcpip',
(self.chain_hos t,
self.chain_port ), peername)
except Exception, e:
verbose('Incomi ng request to %s:%d failed: %s' %
(self.chain_hos t, self.chain_port , repr(e)))
return
if chan is None:
verbose('Incomi ng request to %s:%d was rejected by the SSH
server.' % (self.chain_hos t, self.chain_port ))
return

verbose('Connec ted! Tunnel open %r -%r -%r' % (peername,

chan.getpeernam e(), (self.chain_hos t, self.chain_port )))
while True:
r, w, x = select.select([self.request, chan], [], [])
if self.request in r:
data = self.request.re cv(1024)
if len(data) == 0:
break
chan.send(data)
if chan in r:
data = chan.recv(1024)
if len(data) == 0:
break
self.request.se nd(data)
verbose("Curren t Task: %s" %
(str(stackless. getcurrent()),) )
verbose("Schedu ling Tasks: %s" %
(str(stackless. getruncount()), ))
stackless.sched ule()
chan.close()
self.request.cl ose()
verbose("Exitin g Handler.handle" )
verbose('Tunnel closed from %r' % (peername,))
def forward_tunnel( glovia, local_port, remote_host, remote_port,
transport):
class SubHandler (Handler):
chain_host = remote_host
chain_port = remote_port
ssh_transport = transport
ForwardServer(( '', local_port), SubHandler).ser ve_forever(glov ia)

stackless.taskl et(forward_tunn el)(glovia, LOCAL_PORT, HOST,
REMOTE_PORT, client.get_tran sport())
stackless.run()
</pre>
Oct 9 '08 #1
0 943

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1337
by: Christian Tismer | last post by:
As already announced, the *********************************************** *** *** *** S t a c k l e s s S p r i n t *** *** *** *********************************************** has now a settled date: It will take place in Berlin, March 10-14 2004.
0
2066
by: hanjar | last post by:
Hello, I'm using paramiko 0.9 to access one of my home machines and then execute a command. But with the script included below, the command gets executed on the 2nd to 6th go, never on the first. And the commands aren't that commplicated, they are usualy 'touch some-file' or 'cp some_file to /tmp/a'. Am I misunderstanding the paramiko's API or ... ?
4
2280
by: Christian Tismer | last post by:
Dear Former Stackless Users, I have to use this list to announce something really bad to you, since all the Stackless lists are defunct: The Stackless project is finally dead, now and forever. If this doesn't affect you, please don't worry and just ignore it. I don't take any responsibilities for any harm brought to you, your family or your descendants
28
4845
by: Matt Leslie | last post by:
Hi, I'm trying to use microthreads under stackless python, since they sound like exactly what I am after, but I am having very little success. I've got a fresh install of python 2.3.3 from python.org, then downloaded the binary python2.3 release of stackless python from www.stackless.com. This contained three files: python23.dll, python23.lib, python23.exp
2
5164
by: eight02645999 | last post by:
hi i downloaded paramiko and was trying to create private/pub key pairs from the docs, i use this method to create private key import paramiko k = paramiko.RSAKey.generate(1024) k.write_private_key_file("test_priv") How do i generate the public key for this ? thanks
1
2406
by: Terry Reedy | last post by:
"Praveena B" <praveena_python@yahoo.comwrote in message news:808793.504.qm@web44809.mail.sp1.yahoo.com... when i used paramiko in python2.5 i got the error below. File "C:\praveena\python scripts\sshlib\ssh.py", line 5, in <module> import paramiko File "C:\Python25\Lib\site-packages\paramiko\__init__.py", line 69, in <module> from transport import randpool, SecurityOptions, Transport File...
1
3859
by: sa6113 | last post by:
I use this code : import paramiko import socket hostname = "192.168.1.4" username = "test" port = 22 password = ''123456"
0
997
by: sa6113 | last post by:
I am using this code to connect to a windows machine using paramiko, I have installed sshd on the machine and it works properly: sock.connect((hostname, port)) t = paramiko.Transport(sock) event = threading.Event() t.start_client(event) event.wait() if not t.is_active(): print 'SSH negotiation failed.'
0
1372
by: sa6113 | last post by:
I want to connect to a Windows machine in my network , using ssh, I use paramiko but I have problem in authentication, would you please help me? 1- I have installed freeSSHD in server machine? Is it necessery ? or may I have to install another program? 2- I have entered server's Ip insted of hostname.Is it correct? 3- I have creat a user in server machine with a password to connect. Am I right?
0
9164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8898
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3051
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2332
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.