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>you're forgetting to call the mother class constructor to specify target. It's not java, and <code>run</code> has no particular meaning. By default, target is <code>None</code> and the thread does nothing.</p>

<pre><code>import threading

class FileScanThread(threading.Thread):
    def __init__(self, myFileName):
        threading.Thread.__init__(self,target=self.run)
        # another syntax uses "super", which is simpler in python 3
        # super().__init__(target=self.run)

        print("In File Scan Thread")
        self.mapFile = myFileName
        #myjar=myFileName
        self.start()

    def run(self):
        print(self.mapFile)

x= FileScanThread("myfile.txt")

x.join()  # when you're done
</code></pre>

python multithreading