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

reload function which is inside another function #6

Open
rushilV opened this issue Dec 31, 2019 · 2 comments
Open

reload function which is inside another function #6

rushilV opened this issue Dec 31, 2019 · 2 comments

Comments

@rushilV
Copy link

rushilV commented Dec 31, 2019

Environment : Linux os
Hi am trying to reload the function which is present within another function like this:

async def run():
    print("RUN Component")
    @reloadr
     async def function2():
          print("Function 2")
          return 0
      while True:
          await function2()
          sleep(5)

and calling that in while loop.
The problem here is when i change the print statement in function2 and save it am getting the following error and the value printing is still the old one.

**Error**
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/home/pop/.local/lib/python3.6/site-packages/watchdog/observers/api.py", line 199, in run
    self.dispatch_events(self.event_queue, self.timeout)
  File "/home/pop/.local/lib/python3.6/site-packages/watchdog/observers/api.py", line 368, in dispatch_events
    handler.dispatch(event)
  File "/home/pop/.local/lib/python3.6/site-packages/watchdog/events.py", line 330, in dispatch
    _method_map[event_type](event)
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 89, in on_modified
    this._reload()
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 146, in _reload
    self._target = reload_function(self._target, self._filepath)
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 63, in reload_function
    return reload_target(target, 'def', filepath)
  File "/home/pop/.local/lib/python3.6/site-packages/reloadr.py", line 50, in reload_target
    exec(source, module.__dict__, locals_)
  File "<string>", line 2
    def function2():
    ^
IndentationError: unexpected indent
@rushilV
Copy link
Author

rushilV commented Dec 31, 2019

However my indentations are correct the same code will run perfectly when initialized as separate function i.e outside of the main function

@hoh
Copy link
Owner

hoh commented Jan 30, 2020

This is not supported yet, and would be more complex to implement as it would require accessing the namespace of the other function.

Do you have a usecase for this ?

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

No branches or pull requests

2 participants