Python method not executed
<p>Total noob here. I'm trying to create a python object and execute methods in an instance therein and it seems the code block I want to execute just won't run. The code block in question is run_job which when called just seems to do nothing. What am I doing wrong?</p>

<pre><code>import datetime
import uuid
import paramiko


class scan_job(object):

    def __init__(self, protocol, target, user_name, password, command):
        self.guid = uuid.uuid1()
        self.start_time = datetime.datetime.now()
        self.target = target
        self.command = command
        self.user_name = user_name
        self.password = password
        self.protocol = protocol
        self.result = ""

    def run_job(self):
        if self.protocol == 'SSH':
            ssh = paramiko.SSHClient()
            ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
            try:
                print "creating connection"
                ssh.connect(self.target, self.user_name, self.password)
                print "connected"
                stdin, stdout, stderr = ssh.exec_command(self.command)
                for line in stdout:
                    print '... ' + line.strip('\n')
                    self.result += line.strip('\n')
                yield ssh
            finally:
                print "closing connection"
                ssh.close()
                print "closed"

        else:
            print "Unknown protocol"

    def show_command(self):
        print self.command


test = scan_job('SSH', '192.168.14.10', 'myuser', 'mypassword', 'uname -n')

test.show_command()

test.run_job()
</code></pre>

<p>Your method contains a yield statement, which makes it a generator. Generators are evaluated lazily. Consider:</p>

<pre><code>&gt;&gt;&gt; def gen():
...   yield 10
...   yield 3
...   yield 42
... 
&gt;&gt;&gt; result = gen()
&gt;&gt;&gt; next(result)
10
&gt;&gt;&gt; next(result)
3
&gt;&gt;&gt; next(result)
42
&gt;&gt;&gt; 
</code></pre>

<p>This is likely not what you intended to do. </p>

python python-2.7