Coder Social home page Coder Social logo

pyfswatch's People

Contributors

chris-chambers avatar echrisinger avatar paul-nameless avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

pyfswatch's Issues

signal only works in main thread of the main interpreter

Kia ora!

Thanks for the great wrapper. I am attempting to use fswatch and tkinter to monitor the filesystem and display a GUI of changes. The trickiness is that monitor.start() and window.mainloop() (from TK) are both blocking calls. The TK mainloop is also not threadsafe, and must be run from the main thread. Therefore, I am trying to use fswatch from a thread.

I am trying to do essentially this, where the boot()function calls monitor.start(), but it then crashes, raising the following exception.

def main():
    # This starts the fswatch monitor
    control_thread = Thread(target=boot, daemon=True)
    control_thread.start()
    
    # This starts the TK loop
    window.after(0, check_queue)
    window.mainloop()

def boot():
    monitor = Monitor()
    monitor.set_recursive()

    for directory in DIRECTORIES:
        monitor.add_path(directory["path"])

    monitor.set_callback(callback)
    monitor.start()

I'm not super good at this stuff, so any help would be appreciated!

Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 954, in _bootstrap_inner
    self.run()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/threading.py", line 892, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/finnlesueur/Git/tooDo/tooDo.py", line 152, in boot
    monitor.start()
  File "/Users/finnlesueur/Git/tooDo/venv/lib/python3.9/site-packages/fswatch/fswatch.py", line 49, in start
    signal.signal(signal.SIGINT, self._handle_signal)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread of the main interpreter

import error

By
from fswatch import Monitor

The error is : undefined symbol: fsw_init_library
What happens and how to resolve it?
Thanks a lot .

Feature request: Add Monitor.stop()

When looking at the Monitor API, I expected a stop() method, to call libfswatch's fsw_stop_monitor(). I suggest adding such a method to class Monitor

flags arg is invalid

While experimenting with Monitor today, I could capture fs events as per the example, but I could not determine the actual event-type that had occurred for the file in question (e.g. created, updated, etc.). I think flags is supposed to be an array of fsw_event_flag's, and flags_num is supposed to be the size of that array. However, flags (at the Python level) is an int, so I can't traverse the array. I think it's the memory address that has the array. based on this. Maybe that should be a ctypes.POINTER(ctypes.c_int).

Also, while I'm on the subject: what's the purpose of the event_num arg to the callback? If it's "number of events", that doesn't make sense for the monitor callback, which (from what I can tell) is called with one event. The lower-level callback takes two args (events, event_num), and there it does make sense.

Thanks.

AttributeError: dlsym(RTLD_DEFAULT, fsw_init_library): symbol not found

#!/usr/bin/env python
from fswatch import Monitor

monitor = Monitor()
monitor.add_path("/tmp/test/")

def callback(path, evt_time, flags, flags_num, event_num):
    print(path.decode())

monitor.set_callback(callback)
monitor.start()

produces

Traceback (most recent call last):
  File "./monitor.py", line 3, in <module>
    from fswatch import Monitor
  File "/Users/gmartins/opt/anaconda3/lib/python3.7/site-packages/fswatch/__init__.py", line 2, in <module>
    from .fswatch import Monitor
  File "/Users/gmartins/opt/anaconda3/lib/python3.7/site-packages/fswatch/fswatch.py", line 4, in <module>
    from fswatch import libfswatch
  File "/Users/gmartins/opt/anaconda3/lib/python3.7/site-packages/fswatch/libfswatch.py", line 9, in <module>
    fsw_init_library = lib.fsw_init_library
  File "/Users/gmartins/opt/anaconda3/lib/python3.7/ctypes/__init__.py", line 377, in __getattr__
    func = self.__getitem__(name)
  File "/Users/gmartins/opt/anaconda3/lib/python3.7/ctypes/__init__.py", line 382, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, fsw_init_library): symbol not found

on

[Python 3.7.6 ]
         Executable: /Users/gmartins/opt/anaconda3/bin/python
            Version: 3.7.6.final.0
Installation Prefix: /Users/gmartins/opt/anaconda3
      Site Packages: /Users/gmartins/opt/anaconda3/lib/python3.7/site-packages
     Implementation: CPython
             Branch: 
           Revision: 
           Compiler: Clang 4.0.1 (tags/RELEASE_401/final)
         Build Date: Jan  8 2020 13:42:34
In [7]: platform.system()                                                                                                                                                                              
Out[7]: 'Darwin'

In [8]: platform.release()                                                                                                                                                                             
Out[8]: '19.5.0'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.