# Local mode - live update a python script

**URL:** <https://forums.balena.io/t/local-mode-live-update-a-python-script/43779>\
**Category:** Product support\
**Created:** [November 13, 2019, 12:06am UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779 "2019-11-13T00:06:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![smagness](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/smagness/32/2724_2.png) [@smagness](https://forums.balena.io/u/smagness)\
**Post date:** [November 13, 2019, 12:06am UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/1 "2019-11-13T00:06:40Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chrisys](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/chrisys/32/1731_2.png) [@chrisys](https://forums.balena.io/u/chrisys)\
**Post date:** [November 13, 2019, 12:34am UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/2 "2019-11-13T00:34:27Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![smagness](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/smagness/32/2724_2.png) [@smagness](https://forums.balena.io/u/smagness)\
**Post date:** [November 13, 2019, 1:03am UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/4 "2019-11-13T01:03:45Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![gelbal](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/gelbal/32/1109_2.png) [@gelbal](https://forums.balena.io/u/gelbal)\
**Post date:** [November 13, 2019, 10:48am UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/6 "2019-11-13T10:48:47Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![smagness](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/smagness/32/2724_2.png) [@smagness](https://forums.balena.io/u/smagness)\
**Post date:** [November 13, 2019, 9:41pm UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/8 "2019-11-13T21:41:14Z")

</div>

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!
```

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [November 13, 2019, 10:58pm UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/9 "2019-11-13T22:58:56Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![shaunmulligan](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/shaunmulligan/32/34_2.png) [@shaunmulligan](https://forums.balena.io/u/shaunmulligan)\
**Post date:** [November 13, 2019, 11:05pm UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/11 "2019-11-13T23:05:38Z")

</div>

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](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!

---

<div class="post-metadata">

**Author:** ![robertgzr](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/robertgzr/32/1387_2.png) [@robertgzr](https://forums.balena.io/u/robertgzr)\
**Post date:** [December 17, 2019, 2:34pm UTC](https://forums.balena.io/t/local-mode-live-update-a-python-script/43779/12 "2019-12-17T14:34:50Z")

</div>

Hi just updating this thread that the issue linked in the previous post just closed and the fix will make it’s way into an upcoming release of balena-cli, see here: [https://github.com/balena-io/balena-cli/pull/1538](https://github.com/balena-io/balena-cli/pull/1538)
