python - Check for open text file -
i'm writing python application opens several text files in different threads. want each thread make operations on file while open. when external text editor closes file processing of corresponding thread should stop. need check on whether text file still opened or not.
class mythread (thread): def __init__(self, sf): thread.__init__(self) self.sf = sf # sourcefile def run (self): subprocess.popen([editor, self.sf])
the problem subprocess opens file in editor , run() terminates. how can keep run() open until close file externally?
did try subprocess.call method?
subprocess.call('notepad')
this waits command complete before process terminates , returns control program.
this wrote:
import subprocess threading import thread
class mythread(thread): def __init__(self, sf): thread.__init__(self) self.sf = sf def run(self): subprocess.call('notepad ' + self.sf) def main(): mythread = mythread('test.txt') mythread.start() while mythread.isalive(): print "still alive" if __name__ == '__main__': main()
the program keeps printing "still alive" till close notepad window.
Comments
Post a Comment