Local mode - live update a python script

I’m playing with local mode and the live-update functionality. My application is a single container that just runs a python script:

while True:
        print("Hello balena")
        time.sleep(1)

When I edit the .py file to print(“Hello world”) I get:

[Logs]    [2019-11-13 12:57:54] [main] Hello balena!
[Live]    Detected changes for container main, updating...
[Logs]    [2019-11-13 12:57:55] [main] Hello balena!
[Live]    [main] Restarting service...
[Logs]    [2019-11-13 12:57:56] [main] Hello balena!
[Logs]    [2019-11-13 12:57:58] Service exited 'main sha256:4f7b88cd46fbbad1513d62dbd284f73d63e3686c3bac77fa5c184d7441a6a274'
[Logs]    [2019-11-13 12:58:00] Restarting service 'main sha256:4f7b88cd46fbbad1513d62dbd284f73d63e3686c3bac77fa5c184d7441a6a274'
[Logs]    [2019-11-13 12:57:56] [main] Hello balena!
[Logs]    [2019-11-13 12:58:01] [main] []
[Logs]    [2019-11-13 12:58:01] [main] Hello balena!

So the change to “Hello world” has not actually been propagated to the device?

@smagness that should absolutely be working as you expect; the live update is an awesome feature and should reflect that change almost instantly. Can you share your Dockerfile so we can take a look?

Minimal Dockerfile and python:

Dockerfile:

FROM balenalib/raspberrypi3-python:3.7
COPY ./ ./
CMD [ "python3", "main.py" ]

main.py (next to Dockerfile):

import time

while True:
    print("Hello balena!")
    time.sleep(1)

I then do:

balena push <ip> 

and eventually start seeing:

[Logs]    [2019-11-13 13:55:45] [main] Hello balena!
[Logs]    [2019-11-13 13:55:49] [main] Hello balena!

Then when I edit main.py on the local machine:

[Logs]    [2019-11-13 14:00:28] [main] Hello balena!
[Debug]   Got an add filesystem event for service: main. File: main.py
[Logs]    [2019-11-13 14:00:29] [main] Hello balena!
[Logs]    [2019-11-13 14:00:30] [main] Hello balena!
[Live]    Detected changes for container main, updating...
[Logs]    [2019-11-13 14:00:31] [main] Hello balena!
[Logs]    [2019-11-13 14:00:32] [main] Hello balena!
[Live]    [main] Restarting service...
[Logs]    [2019-11-13 14:00:33] [main] Hello balena!
[Logs]    [2019-11-13 14:00:35] Service exited 'main sha256:ff6f08ae4689ec872293f2f2202e2dc693253b8ffd9c1a7ed59d469fb3a666ad'
[Logs]    [2019-11-13 14:00:37] Restarting service 'main sha256:ff6f08ae4689ec872293f2f2202e2dc693253b8ffd9c1a7ed59d469fb3a666ad'
[Logs]    [2019-11-13 14:00:33] [main] Hello balena!
[Logs]    [2019-11-13 14:00:36] [main] Hello balena!

This is with development balenaOS 2.44 with supervisor 10.2.2 (as per my other recent post)

Hi @smagness, I tested your setup with a RPi4 running balenaOS 2.44.0+rev3 and supervisor 10.3.7 and also with a RPi3 running balenaOS 2.43.0+rev1 and supervisor 10.2.2. It works totally fine as expected on my end.

The default supervisor version that comes with balenaOS 2.44.0+rev3 is 10.3.7. I downloaded it from the balenaCloud dashboard. How did you install the supervisor version 10.2.2 with the OS 2.44?

Could you test your scenario again with the version balenaOS 2.44.0+rev3 on RPi4 or balenaOS 2.43.0+rev1 on RPi3?

Apologies, OS is 2.43.0+rev1.

I tried again with a clean SD card. I created a new application and a new device with no source and then put the device straight into local mode once it came online in balenaCloud. From my Windows machine I then do 'balena push ’ and the same problem occurs - when I change main.py the console suggests it has noticed the change and restarts the container, but the change has not been effected.

If I then disconnect (Ctrl + C) and re-run 'balena push ’ I continue to get “hello balena!” briefly and then after 5-10 seconds it does kill the service and spin up a new one with the new code (“hello world!”):

[Logs]    [2019-11-14 10:37:44] [main] Hello balena!
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:45] [main] Hello balena!
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:46] [main] Hello balena!
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:47] [main] Hello balena!
[Logs]    [2019-11-14 10:37:48] [main] Hello balena!
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:51] Service exited 'main sha256:bb2b99b095e9e949c6ec0788288f9a75cd8c69af3fcc9061356d63fdb02b1b7f'
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:51] Killed service 'main sha256:bb2b99b095e9e949c6ec0788288f9a75cd8c69af3fcc9061356d63fdb02b1b7f'
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:52] Installing service 'main sha256:f192dd8f2e6e174467fc18b187903465e8696a9b2b4c270e5279d45753bdf302'
[Logs]    [2019-11-14 10:37:52] Installed service 'main sha256:f192dd8f2e6e174467fc18b187903465e8696a9b2b4c270e5279d45753bdf302'
[Logs]    [2019-11-14 10:37:52] Starting service 'main sha256:f192dd8f2e6e174467fc18b187903465e8696a9b2b4c270e5279d45753bdf302'
[Logs]    [2019-11-14 10:37:54] Started service 'main sha256:f192dd8f2e6e174467fc18b187903465e8696a9b2b4c270e5279d45753bdf302'
[Logs]    [2019-11-14 10:37:54] [main] Hello world!
[Debug]   Device state not settled, retrying in 1000ms
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [2019-11-14 10:37:55] [main] Hello world!

Hi Steve, I think the [Debug] Device state not settled, retrying in 1000ms logs seem to indicate it can’t get the state of the device. Could you describe your windows set up a bit more, most interesting to us would be what Windows version and what terminal/console you are using to run balena push?

Oh sorry, I actually just found that there is a known issue with livepush on windows (see github issue: https://github.com/balena-io-modules/livepush/issues/55 ) where it can’t handle copying properly from the filesystem because of the windows paths. We are trying to prioritise fixing this currently. Sorry about that!

1 Like