getnikola / nikola

A static website and blog generator
https://getnikola.com/
MIT License
2.62k stars 449 forks source link

nikola auto loops infinitely #3638

Closed catlee closed 1 year ago

catlee commented 2 years ago

Environment

Python Version: 3.7.13

Nikola Version: 8.2.3

Operating System: Debian

Description:

When I run nikola auto for my site and load the local url in the browser, sometimes after making some changes to a blog post the site will reload over and over again.

In the terminal where nikola auto is running I can see it refreshing a lot of the posts/taxonomies and site xml files. I end up having to interrupt the process, restart it, and reload my browser.

Let me know if there's anything I can do to help debug this!

gipi commented 1 year ago

I checked this problem since made practically un-usable nikola for me and I don't know if I'm crazy or what but the code for handling the filesystem events doesn't make sense:

# Based on code from the 'hachiko' library by John Biesnecker — thanks!
# https://github.com/biesnecker/hachiko
class NikolaEventHandler:
    """A Nikola-specific event handler for Watchdog. Based on code from hachiko."""

    def __init__(self, function, loop):
        """Initialize the handler."""
        self.function = function
        self.loop = loop

    async def on_any_event(self, event):
        """Handle all file events."""
        await self.function(event)

    def dispatch(self, event):
        """Dispatch events to handler."""
        self.loop.call_soon_threadsafe(asyncio.ensure_future, self.on_any_event(event))

if I get this right, this code is putting in the queue any event, also opening a file. If I filter on FileModifiedEvent then it works.