roipoussiere / cadquery-server

A web server used to render 3d models from CadQuery code loaded dynamically.
MIT License
50 stars 17 forks source link

Watchdog thread is dead when it's conflict with save #74

Open ikeji opened 1 year ago

ikeji commented 1 year ago

Sometime the watchdog thread is dead when save the module from editor and stop updating UI anymore.

Steps to produce:

What I got:

Exception in thread Thread-1 (watchdog):
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/site-packages/cq_server/server.py", line 73, in watchdog
    last_updated_file = module_manager.get_last_updated_file()
  File "/usr/local/lib/python3.10/site-packages/cq_server/module_manager.py", line 97, in get_last_updated_file
    module_path, timestamp = self.get_most_recent_module()
  File "/usr/local/lib/python3.10/site-packages/cq_server/module_manager.py", line 83, in get_most_recent_module
    timestamp = op.getmtime(module_path)
  File "/usr/local/lib/python3.10/genericpath.py", line 55, in getmtime
    return os.stat(filename).st_mtime
FileNotFoundError: [Errno 2] No such file or directory: '/data/main.py'

Why this happen:

Some editor like vim do follow steps when save: (When I edit main.py)

  1. Rename existing main.py to main.py~
  2. Write new content to main.py
  3. Remove main.py~

When the watchdog thread call op.getmtime after 1 but before 2, the main.py is not exist.

I think we can ignore this error and retry in next tick.

Thanks