# Infinite 'watchthemes' compile loop

**URL:** <https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968>\
**Category:** Development\
**Tags:** theming, tutor, quince\
**Created:** [May 10, 2024, 9:54am UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968 "2024-05-10T09:54:00Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![burkay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/burkay/32/5144_2.png) [@burkay](https://discuss.openedx.org/u/burkay)\
**Post date:** [May 10, 2024, 9:54am UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/1 "2024-05-10T09:54:00Z")

</div>

Hi all.

I’ve been working on devstack for a while, but I reinstalled the tutor. I’m running into a problem I haven’t encountered before. When I create a custom theme, when I add anything to the styles, `watchthemes` goes into an endless compilation loop. I can see the changes I made in `css/lms-main-v1.css`, but it keeps recompiling. After a while cpu and ram are 200-300% and the computer freezes. I have never encountered such a problem before. After installing the latest version, I encounter such a problem. Can you help?

 ![compile-error-1](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/8/8e2014c41528d0c7135b78833cddbd3e7c6b842b.jpeg)  
 ![compile-error-2](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/9/90b80d097ee2820d56c5eca1748fa3aeb90d24fd.jpeg)  
 ![cpu-error](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/4/4558fd96117d1eae5ef9531948113c44d05cd424.jpeg)

**tutor, version 17.0.4**

---

<div class="post-metadata">

**Author:** ![devpt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/devpt/32/6453_2.png) [@devpt](https://discuss.openedx.org/u/devpt)\
**Post date:** [May 10, 2024, 10:09am UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/2 "2024-05-10T10:09:11Z")

</div>

happened every version

---

<div class="post-metadata">

**Author:** ![burkay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/burkay/32/5144_2.png) [@burkay](https://discuss.openedx.org/u/burkay)\
**Post date:** [May 10, 2024, 10:30am UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/3 "2024-05-10T10:30:33Z")

</div>

Has this problem occurred after a new update? It was working fine before.

---

<div class="post-metadata">

**Author:** ![WillEVTdigital](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/willevtdigital/32/6667_2.png) [@WillEVTdigital](https://discuss.openedx.org/u/WillEVTdigital)\
**Post date:** [May 10, 2024, 2:56pm UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/4 "2024-05-10T14:56:50Z")

</div>

I’ve had the same issue - I couldn’t debug, but looks to be some sort of memory leak.

I had trouble with `tutor config save` copying all the theme files across in one go, overwriting existing even when identical, which then causes the compilation loop.

This can be a problem when restarting the dev environment as if you’ve previously run `watchthemes` and the container’s been built it will spin up on every `tutor dev start` / `tutor dev restart all` / `tutor dev launch`.

A bit of a pain but you can get the docker container id, and stop it once you’ve spun up tutor.

You can then re-run `watchthemes` when you need it.

To copy only updated files `env/build/openedx/themes` directory I made a script:

```auto
#!/bin/bash

# Define the source and target directories
SOURCE_DIR="/home/path/to/forked/tutor-indigo/templates"
TARGET_DIR="/path/to/.local/share/tutor/env/build/openedx/themes"

# Make sure inotifywait and rsync are installed
if ! command -v inotifywait &> /dev/null || ! command -v rsync &> /dev/null
then
    echo "inotifywait and rsync are required for this script to run."
    exit 1
fi

# Function to synchronise the changed file or delete it if necessary
sync_or_delete_file() {
    local event_type="$1"
    local source_directory="$2"
    local file_name="$3"
    local relative_directory="${source_directory//$SOURCE_DIR/}"
    echo "Relative dir: $relative_directory"

    if [["$event_type" == *"DELETE"* || "$event_type" == *"MOVED_FROM"*]]; then
        # If the file was deleted or moved from, delete it from the target
        local target_file="${TARGET_DIR}/${file_name}"
        rm -f "$target_file"
        echo "File deleted: $target_file at $(date)"
    else
        # For other events, use rsync to synchronise the specific file
        local source_file="${source_directory}${file_name}"
        local target_file_dir="$(dirname "${TARGET_DIR}${relative_directory}/${file_name}")"
        mkdir -p "$target_file_dir" # Ensure target directory exists
        rsync -av "$source_file" "$target_file_dir"
        echo "File synchronised: $source_file to $target_file_dir at $(date)"
    fi
}

# Watch for changes in the source directory and act on them
inotifywait -m -r -e modify,create,delete,move "$SOURCE_DIR" --format '%:e %w %f' |
while IFS=' ' read -r event directory file; do
    # Filter out events that are not directly related to file changes
    if [["$event" == "CREATE,ISDIR" || "$event" == "MODIFY,ISDIR"]]; then
        continue # Skip directory-related events for now
    fi
    
    # For move events, adjust to capture the destination file name
    if [["$event" == "MOVED_TO" || "$event" == "MOVED_FROM"]]; then
        read -r additional_event additional_file
        if [["$additional_event" == "MOVED_TO" && "$event" == "MOVED_FROM"]]; then
            file="$additional_file" # Use the destination file name
        fi
    fi
    echo "Dir: $directory"

    sync_or_delete_file "$event" "$directory" "$file"
done

```

---

<div class="post-metadata">

**Author:** ![burkay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/burkay/32/5144_2.png) [@burkay](https://discuss.openedx.org/u/burkay)\
**Post date:** [May 15, 2024, 5:05pm UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/5 "2024-05-15T17:05:21Z")

</div>

Thanks for answer.

Actually, so did i like your said;

I stoped watchthemes `tutor dev stop watchthemes` after the `tutor dev start` then, when changes some style and run `tutor dev run watchthemes`. Yes, this method works but if don’t stop this watchthemes just in time, it is entering the infinite loop again and to be hard for stop the container with this method.

Do you know of a manual method for compiling the SCSS files?

---

<div class="post-metadata">

**Author:** ![WillEVTdigital](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/willevtdigital/32/6667_2.png) [@WillEVTdigital](https://discuss.openedx.org/u/WillEVTdigital)\
**Post date:** [May 15, 2024, 5:26pm UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/6 "2024-05-15T17:26:24Z")

</div>

No problem. You can use the following instead of watchthemes. It’s a pain to have to manually trigger it, but it’s better than a container with a memory leak!

Compiling themes’ SCSS:

```auto
tutor dev run lms ./manage.py lms compile_sass

```

Collecting static build assets:

```auto
tutor dev run lms ./manage.py lms collectstatic --noinput && ./manage.py cms collectstatic --noinput

```

I came across them [here](https://docs.openedx.org/projects/edx-platform/en/latest/decisions/0017-reimplement-asset-processing.html)

---

<div class="post-metadata">

**Author:** ![burkay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/burkay/32/5144_2.png) [@burkay](https://discuss.openedx.org/u/burkay)\
**Post date:** [May 15, 2024, 6:23pm UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/7 "2024-05-15T18:23:21Z")

</div>

These are very useful for me for now. I don’t know how I didn’t come across this link before. Thanks so much for your help

---

<div class="post-metadata">

**Author:** ![WillEVTdigital](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/willevtdigital/32/6667_2.png) [@WillEVTdigital](https://discuss.openedx.org/u/WillEVTdigital)\
**Post date:** [May 16, 2024, 6:12am UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/8 "2024-05-16T06:12:56Z")

</div>

No worries! Some of these things are quite well hidden 😅

---

<div class="post-metadata">

**Author:** ![burkay](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/burkay/32/5144_2.png) [@burkay](https://discuss.openedx.org/u/burkay)\
**Post date:** [May 16, 2024, 12:23pm UTC](https://discuss.openedx.org/t/infinite-watchthemes-compile-loop/12968/9 "2024-05-16T12:23:08Z")

</div>

Yes, I agree about hiding 😄 If you hadn’t told me, I probably wouldn’t have found this link.
