hoh / reloadr

Hot code reloading tool for Python
GNU Lesser General Public License v3.0
527 stars 12 forks source link

Trigger reloader from somewhere else. #10

Open stuaxo opened 3 years ago

stuaxo commented 3 years ago

I'd like a way of triggering the reloader from somewhere else, and when the code isn't necessarily in a file.

In Shoebot we execute code once per frame that may be in a . New code can arrive from an external editor, which we crudely swap out.

It would be good if if we could use reloadr and call something to tell it that the new code has been updated and what it is.

We have a crude rollback system too - if the code raises and exception or has a syntax error, we roll back to the last known good code and state. Not sure if that's in the scope of reloadr, but would be good, we use that so that the user can edit code as it's drawing animations etc.

stuaxo commented 3 years ago

(I'm not quite sure if this is a dupe of https://github.com/hoh/reloadr/issues/6)

stuaxo commented 3 years ago

Here is out very crude approach to code loading https://github.com/shoebot/shoebot/blob/master/shoebot/grammar/livecode.py#L44

I'm hoping to replace it with something modern.

hoh commented 3 years ago

Generating graphics is one of my motivations for creating reloadr.

Would you have a small video demonstrating how you use the shoebot editor so I can see how your code reloading works for a user ?

stuaxo commented 3 years ago

Here you go:

https://www.youtube.com/watch?v=foxzx0JFU5g

The editor used here is gedit with a plugin. Shoebot gets new code every time the user presses a key. Currently this is via stdout to shoebot as a subprocess - I can show you the code, but the code in shoebot classic is pretty old and crusty now, hence me building something new :)

stuaxo commented 3 years ago

Since code reloading may trigger weird side effects, the user can turn toggle turn it on or off ("live coding") image

hoh commented 3 years ago

Interesting approach with the tenuous mode in shoebot's code.

Do I understand that shoebot will reload every function within the target ?

stuaxo commented 3 years ago

Do I understand that shoebot will reload every function within the target ? Yes, with a bunch of caveats, because it's very dumb:

There are some things unavoidable in this approach ..