Support of pyend instruction for execution of commands right after page serving#68
Open
ftylitak wants to merge 5 commits intojczic:masterfrom
Open
Support of pyend instruction for execution of commands right after page serving#68ftylitak wants to merge 5 commits intojczic:masterfrom
ftylitak wants to merge 5 commits intojczic:masterfrom
Conversation
deleted all comments to save 40KB of data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit adds support of a new instruction {{ pyend }}. {{ pyend }} behaves exactly as the {{ py }} in the manner of including code that will to be executed. Its only specialty is that the code included in the instruction, will be executed in a separate thread after the "generated" html from pyhtml has been served.
Usage: we use it in a microcontroller Web based UI for easy configuration. During the final step of the configuration wizard, the configurations are saved and the device gets rebooted to apply new configuration. In the {{ pyend }} we add the code to wait for a period of time and then power off/on the controller. Its benefit is that the pyhtml page includes a success message, which is first served and then the device gets rebooted, enhancing User Experience.
The alternative of not using this, would be either not to show a success message or to load a new page that would include the reboot code in a {{ py }}.
{{ pyend }} import machine import utime start_time = utime.ticks_ms() WAIT_UNTIL_REBOOT_MSEC = 3000 while (utime.ticks_ms()-start_time < WAIT_UNTIL_REBOOT_MSEC): utime.sleep_ms(1000) machine.reset() {{ end }}We do not know if this is something that you consider useful though we have been using this for a while and we thought it would be better to share.