Threading with subprocess
<p>I am using python 2.7 and new to Threading. I got a class file and run method. But I don't see the run method invoked when I create instances of thread. I am also planning to use <code>subprocess.Popen</code> inside the <code>run</code> method and get <code>stdout</code> of the process for each filename and print the output. </p>

<p>Please tell me what I am missing here for <code>run</code> method to be called.</p>

<pre><code>class FileScanThread(threading.Thread):
    def __init__(self, myFileName):
        print("In File Scan Thread")
        self.mapFile = myFileName
        #myjar=myFileName
        self.start()

    def run(self):
        print self.mapFile

  x= FileScanThread("myfile.txt")
</code></pre>

<p>This will do what you want. You aren't calling <code>__init__</code> from the class Thread.</p>

<pre><code>class FileScanThread(threading.Thread):
    def __init__(self, myFileName):
        threading.Thread.__init__(self)
        print("In File Scan Thread")
        self.mapFile = myFileName
        #myjar=myFileName
        self.start()

    def run(self):
        print self.mapFile

x = FileScanThread("myfile.txt")
</code></pre>

<p>I don't think you have to pass target argument to it. At least that's not usually how I do it. </p>

<p>Output:</p>

<pre><code>In File Scan Thread
myfile.txt
</code></pre>

python multithreading