I have following code:
def handler(self, conf_file):
with open(conf_file, "r") as f:
try:
data = json.load(f)
except json.decoder.JSONDecodeError as line:
exit(code=f"JSON ERROR!\n{line}")
path = f"{current_dir()}/{data['input_folder']}"
event_handler = LoggingEventHandler()
event_handler.on_created = self.on_created(conf_file=conf_file)
observer = Observer()
observer.schedule(event_handler, path, recursive=True)
observer.start()
try:
while True:
time.sleep(1)
finally:
observer.stop()
observer.join()
This code is responsive for watching my folder and calling function to put it in right place depending on extension.
The problem is that then I try to pass path to my config file, so just a string I print me that error:
TypeError: on_created() missing 1 required positional argument: 'event'
Head of called function:
def on_created(self, event, conf_file):
That "event" is passed by watchdog library by default, and I already tried to make that parameter optional but it wasn't passed, but there is next problem.
In that event are some important info for my program like is_dictionary, and src_path and without then nothing will work.
And I can't use global because I will have multiple threads running it and they will use same value and run instantly into error and conflicts and then destroying whole structure.
UPDATE!
Updated code a little bit and heres link to full code:
https://gist.github.com/comand100vip/9ed4e0f1e993991388e82b39b979f19e
Link to .json file:
https://gist.github.com/comand100vip/b0e8bef38889adaa52fd428be7353e3c