From 5df3b8579c91027eda194473093d280da953b864 Mon Sep 17 00:00:00 2001 From: SirWalross <27106448+SirWalross@users.noreply.github.com> Date: Mon, 13 Jun 2022 11:35:51 +0200 Subject: [PATCH] Fix lock mechanism and other small updates --- measure.py | 1 + scripts/pull.bash | 7 ------- scripts/push.bash | 26 ++++++++++++++++++-------- scripts/write.bash | 1 + 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/measure.py b/measure.py index 348363d..d1cabe1 100644 --- a/measure.py +++ b/measure.py @@ -133,6 +133,7 @@ def loop(con1: serial.Serial, con2: serial.Serial): write_data() +@log_profile("main") def main() -> None: print("Starting") try: diff --git a/scripts/pull.bash b/scripts/pull.bash index a71199e..574a5d8 100755 --- a/scripts/pull.bash +++ b/scripts/pull.bash @@ -1,15 +1,8 @@ #!/bin/bash -# wait until all other instances of the script are finished -while pidof -o %PPID -x "pull.bash">/dev/null; do - # check every 60 seconds - sleep 60 -done - cd `dirname "$0"`/.. echo -e "\n\n#####################################################################" echo $( date '+%F %H:%M:%S' ) | tee -a bash.log -git pull 2>&1 | tee -a bash.log echo "" | tee -a bash.log scripts/./push.bash 2>&1 | tee -a bash.log echo "" | tee -a bash.log \ No newline at end of file diff --git a/scripts/push.bash b/scripts/push.bash index 9775700..c882fda 100755 --- a/scripts/push.bash +++ b/scripts/push.bash @@ -1,19 +1,25 @@ #!/bin/bash -ls -la . -ls -la data -ls -la logs +# wait until all other instances of the script are finished +while pidof -x "python3 main.py">/dev/null; do + # check every 60 seconds + echo "python3 main.py is still running, checking in 60 seconds." + sleep 60 +done +sleep 10 + ps aux scripts/./write.bash -pip3 install multiprocessing_logging +sleep 10 + python3 measure.py -git add . -git commit -m "New data" && git push --force +sleep 10 + echo -e "Starting python script:\n" -loop_count = 1 +loop_count=1 while : ; do python3 main.py return_code=$? @@ -28,4 +34,8 @@ while : ; do echo -e "Ended with error, waiting and trying again" loop_count=$((loop_count + 1)) sleep $((loop_count * 60)) -done \ No newline at end of file +done + +git pull +git add . +git commit -m "New data" && git push --force \ No newline at end of file diff --git a/scripts/write.bash b/scripts/write.bash index 02facad..afda628 100755 --- a/scripts/write.bash +++ b/scripts/write.bash @@ -17,6 +17,7 @@ then serial_dms=/dev/ttyACM1 else echo -e "\x1b[31mError: Something went wrong.\x1b[0m" + echo "$id" echo -e "Exiting" exit 1 fi -- GitLab