I will start out by saying I have never done events and triggers in anything other than javascript.
I have a thread that runs and processes all the files in a folder. I want this thread to run everytime a new file writes to that folder. I thought events would be the way to do that, but I have no idea how to do that in python.
How do you tell a thread to throw or trigger an event? How does another thread pick this up?
sample thread:
def list_files_thread(dir):
for filename in os.listdir(dir):
print filename
thread.start_new_thread(list_files_thread, ('output',))
Edit: I am new to mutlithreading, so maybe I should use this instead?
class list_files_thread(threading.Thread):
def __init__(self, directory):
self.directory = directory
def run(self):
list_files(self.directory)
def list_files(directory_path):
for filename in os.listdir(directory_path):
print filename