hoh/reloadr

Errors with simple script

alekratz opened this issue · 3 comments

When using the following script:

from reloadr import autoreload
import time

@autoreload
def foo():
    return 4

if __name__ == "__main__":
    print("Here we go")
    while True:
        print(foo())
        time.sleep(1)

I get this error when I edit and save the foo function:

Exception in thread Thread-40:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/site-packages/watchdog/observers/api.py", line 199, in run
    self.dispatch_events(self.event_queue, self.timeout)
  File "/usr/lib/python3.6/site-packages/watchdog/observers/api.py", line 368, in dispatch_events
    handler.dispatch(event)
  File "/usr/lib/python3.6/site-packages/watchdog/events.py", line 330, in dispatch
    _method_map[event_type](event)
  File "/usr/lib/python3.6/site-packages/reloadr.py", line 89, in on_modified
    this._reload()
  File "/usr/lib/python3.6/site-packages/reloadr.py", line 146, in _reload
    self._target = reload_function(self._target, self._filepath)
  File "/usr/lib/python3.6/site-packages/reloadr.py", line 63, in reload_function
    return reload_target(target, 'def', filepath)
  File "/usr/lib/python3.6/site-packages/reloadr.py", line 45, in reload_target
    source = get_new_source(target, kind, filepath)
  File "/usr/lib/python3.6/site-packages/reloadr.py", line 31, in get_new_source
    red = redbaron.RedBaron(open(filepath).read())
FileNotFoundError: [Errno 2] No such file or directory: '<string>'

I am executing this as python3 reloadtest.py.

hoh commented

Thanks for reporting the issue.
I could reproduce the issue on Linux (Debian 9, Python 3.5), and will investigate further.

Will this ever get fixed? I love this module but getting a massive error in console every time I save the file is pretty annoying.

hoh commented

Hi, I will work on reloadr this at the end of this week, and hope to release a new version then.