How do I get the current path of the file executing the current thread?
Question: In python, I can do this to get the current file's path:

    
    
    os.path.dirname(os.path.abspath(__file__))
    

But if I run this on a thread say:

    
    
    def do_stuff():
       class RunThread(threading.Thread):
           def run(self):
               print os.path.dirname(os.path.abspath(__file__))
       a = RunThread()
       a.start()
    

I get this error:

    
    
    Traceback (most recent call last):
      File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
        self.run()
      File "readrss.py", line 137, in run
        print os.path.dirname(os.path.abspath(__file__))
    NameError: global name '__file__' is not defined
    


Answer: 
    import inspect
    print(inspect.stack()[0][1])
    

[inspect](https://docs.python.org/2/library/inspect.html)

