-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
wait
option does not change the reload cycle
#2285
Comments
Following up here as asked in #2093. From what I understand, the situation I describe in #2093 (and that is originally described in #2061) is not the same as what is described here. OP here seems to be auto-generating a file early in the build process. Apparently it triggers the livereload watcher, so the docs are immediately rebuilt after the first build. And then again since the second build also triggered the watcher. This is why OP mentions a build loop. Am I correct @AnjoMan? If I am, then yes, a delay here is the solution: discard watcher events during the first N seconds. This way the file auto-generation does not trigger a rebuild, and we do not enter a build loop. But even if we use a delay, multiple events occurring after that delay will trigger multiple rebuilds, instead of just one (i.e. a batching update, mentioned by @squidfunk in #2061). What if a watched directory generates 1000 events in the span of 10 seconds? We have to set a 10 seconds delay? Then for every single change we do (for example saving a Markdown page), we'll have to wait 10 seconds before the reload? I'm just asking to make sure I correctly understand the situation. So if I understand correctly, we need another option to wait until a specified period of inactivity is reached, i.e. only trigger the build once no changes were detected since the last N seconds. In my case, even 0.2 seconds would be enough to reduce the number of rebuilds from events times to one time only. I do agree that we must check if the delay feature works in upstream anyway 🙂 @squidfunk have you been able to workaround the multiple rebuild you describe in #2061? |
First of all, all MkDocs does is accept the
This was my understanding of what python-livereload's Finally, if the above is correct and python-livereload does not offer the feature we want/need, then the appropriate way to get that feature is to add the feature to python-livereload. Once python-livereload supports the feature, then we can include support for it. |
Perfect, sorry for thinking we understood it differently! Then I'll try to find time to investigate on python-livereload's side! Thanks @waylan |
This reverts commit f73f221. It seems that the `wait` flag does not interupt the file watcher, but simply delays builds. Therefore, a plugin which writes to the `docs_dir` will still result in an infinite loop. That being the case, the `wait` flag is not useful to us. See mkdocs#2285.
Disregarding the title of this issue, the exact described use case (writing files into docs dir during the build of that docs dir) is not a good approach and, I'd say, should not be catered towards. Instead one can write to a separate temporary directory and add that file into the Files structure. #2061 is a separate issue, and as of now it is indeed not solved, so probably should be reopened. |
@oprypin you make a good point. In fact, that was my response the first few times this came up. However, after repeated requests, I (incorrectly) thought that livereload's
Actually, as #2061 specifically applies to themes, it is addressed in #2094. That said, when the |
#2061 only mentions themes as one example, but the issue applies to any file. I'll comment there. |
Is the idea here to implement the Maybe if there are a lot of requests about doing this kind of thing, we just need to add a bit in the plugin documentation about how I'll try reimplementing my plugin using the suggestion from @oprypin and see if i could come up with a simple explanation for how it works |
BTW instead of implementing this logic, you can very likely just use the plugin itself :)
Yes. It receives the mkdocs/mkdocs/structure/files.py Lines 19 to 20 in 1beaf22
def on_files(self, files : mkdocs.structure.files.Files, config) -> mkdocs.structure.files.Files:
file_list = list(files)
file_list.append(File(......))
return mkdocs.structure.files.Files(file_list) |
Yes, we know. In fact, adding that documentation is part of #1629. But, yes @oprypin is correct. Using the In any event, there is no actionable item in this issue that we will act on that is not already the subject of another issue (#2021 has been reopened). Therefore, I am closing this. |
I wrote a plugin that generates files in
docs_dir
, the general structure of which is:I have been trying to use the
wait
keyword argument (e.g. `mkdocs serve --wait 60) to keep the live-reload feature from watching my auto-generated files before they are updated after a reload, since this would cause a build loop. However, it seems that the wait number has no effect -- as noted in #2284, even if i make the delay extremely long (50,000 seconds) there is no effect on the cycle time.i think this may come down to an issue with the
livereload
package, although it provides the delay option there appears to be no unit tests and its not clear that the feature works. Perhaps it should be rolled back until we can find a better approach for achieving this wait?The text was updated successfully, but these errors were encountered: