logging module usage

2011-03-30 Thread mennis
I am working on a library for controlling various appliances in which
I use the logging module.  I'd like some input on the basic structure
of what I've done.  Specifically the logging aspect but more general
comments are welcome.  I'm convinced I mis-understand something but
I'm not sure what.  I've posted a version of the library at github.

[email protected]:mennis/otto.git
http://github.com/mennis/otto
Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: logging module usage

2011-04-07 Thread mennis
Thank you.  This has been very helpful. 

Ian
-- 
http://mail.python.org/mailman/listinfo/python-list


multiprocess (and paramiko)

2014-06-03 Thread mennis
I was able to work around this by using a completely different design but I 
still don''t understand why this doesn't work.  It appears that the process 
that launches the process doesn't get access to updated object attributes.  
When I set and check them in the object itself it behaves as expected.  When I 
check them from outside the object instance I get the initial values only.  
Could someone explain what I'm missing?

Here I have a simple multiprocessing class that when initializes takes a 
connected SSHClient instance and a command to run on the associated host in a 
new channel.

import multiprocessing

from time import time
from Crypto import Random
import paramiko


class Nonblock(multiprocessing.Process):

def __init__(self, connection, cmd):
Random.atfork()
multiprocessing.Process.__init__(self)

self.transport = connection.get_transport()
if self.transport is None:
raise ConnectionError("connection.get_transport() returned None ")
self.channel = self.transport.open_session()

self.command = cmd
self.done = False
self.stdin = None
self.stdout = None
self.stderr = None
self.status = None
self.message = str()
self.time = float()

def _read(self, channelobj):
"""read until EOF"""
buf = channelobj.readline()
output = str(buf)
while buf:
buf = channelobj.readline()
output += buf
return output

def run(self):

start = time()
stdin, stdout, stderr = self.channel.exec_command(command=self.command)

self.stderr = self._read(stderr)
self.status = stdout.channel.recv_exit_status()

if self.status != 0:
self.status = False
self.message = self.stderr
else:
self.status = True
self.message = self._read(stdout)

self.time = time() - start
stdin.close()

self.done = True


I expect to use it in the following manner:

from simplelib import Nonblock
from time import sleep
from paramiko import SSHClient, AutoAddPolicy


if __name__== "__main__":
connection = SSHClient()
connection.set_missing_host_key_policy(AutoAddPolicy())

username = "uname"
hostname = "hostname"
password = "password"

connection.connect(hostname, 22, username, password)
print connection.exec_command("sleep 1; echo test 0")[1].read()

n = Nonblock(connection,"sleep 20; echo test 2")
n.start()

print connection.exec_command("sleep 1; echo test 1")[1].read()
while not n.done:
sleep(1)
print n.message
print "done"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: multiprocess (and paramiko)

2014-06-03 Thread mennis
I'm familiar with and have learned much from fabric.  Its execution model don't 
work for this specific interface I'm working on.  I use fabric for other things 
though and it's great.

Ian
-- 
https://mail.python.org/mailman/listinfo/python-list