paul-nameless / pyfswatch Goto Github PK
View Code? Open in Web Editor NEWPython binding to libfswatch
License: MIT License
Python binding to libfswatch
License: MIT License
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
By
from fswatch import Monitor
The error is : undefined symbol: fsw_init_library
What happens and how to resolve it?
Thanks a lot .
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
pip install fswatch
installs a version prior to this bugfix: c138338
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.
#!/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'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.