Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileSystemEventHandler on MAC OS not working anymore #713

Closed
rburchDev opened this issue Dec 2, 2020 · 2 comments
Closed

FileSystemEventHandler on MAC OS not working anymore #713

rburchDev opened this issue Dec 2, 2020 · 2 comments

Comments

@rburchDev
Copy link

The below script was working previously on my Mac. Now the on_created event handler never fires. This same script works on my Ubuntu machine.

try:
    base_path = os.environ['EVOLVE_HOME']
except KeyError:
    print('Could not get environment variable "base_path". This is needed for the tests!"')
    raise

def ram_recorder():  # Thread to extract new data from RAM text files into CSV file with timestamp
    class RAMHandler(FileSystemEventHandler):  # Watchdog folder monitor Class
        def on_created(self, event):  # When file is created in monitored folder
            global client  # Call global variables set outside of Class
            new_ram = str(event.src_path)  # Extract filepath from new file in monitored folder
            time.sleep(.5)
            line = linecache.getline(new_ram, 3)
            r_base = os.path.basename(new_ram)  # Strip filepath too base file name
            r_nano = int(r_base.strip('RAM_ .txt'))  # Strip nanosecond time from file name
            if "MemAvailable" in line:
                mem = int(line.strip("MemAvailable: \n kB"))
                body = [
                    {
                        "measurement": "Evolve",
                        "tags": {
                            "Software": version,
                        },
                        "time": r_nano,
                        "fields": {
                            "RAM": mem,
                        }
                    }
                ]
                client.write_points(body)
                return r_nano

    r_observer = Observer()
    r_event_handler = RAMHandler()
    r_observer.schedule(r_event_handler, path=os.path.join(base_path, 'test'), recursive=False)  # Folder to monitor
    r_observer.start()

I am running the following:

  • Python 3.9
  • Mac OS 11.0.1
  • Watchdog 0.10.4
@BoboTiG
Copy link
Collaborator

BoboTiG commented Dec 2, 2020

See #702.

@BoboTiG BoboTiG closed this as completed Dec 2, 2020
@rburchDev
Copy link
Author

Thanks! I figured, but wanted confirmation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants