Skip to content

Commit c9f480c

Browse files
Merge pull request #94 from github-samples/windows-updates
Windows updates
2 parents 409b31f + 4063612 commit c9f480c

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

content/1-hour/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ You will also need the following available and installed locally:
3434

3535
- A recent [Node.js runtime][nodejs-link].
3636
- A recent version of [Python][python-link].
37+
- For Windows, you can install [Python via the Windows store](https://apps.microsoft.com/detail/9pjpw5ldxlz5?hl=en-US&gl=US).
3738
- The [git CLI][git-link].
3839
- A shell capable of running BASH commands.
3940

@@ -65,5 +66,6 @@ Ready to get started? Let's go! The workshop scenario imagines you as a develope
6566
[stage-4]: ./4-add-feature.md
6667
[walkthrough-previous]: ../README.md
6768
[walkthrough-next]: ./0-setup.md
69+
[windows-python-link]: https://apps.microsoft.com/detail/9pjpw5ldxlz5
6870
[windows-subsystem-linux]: https://learn.microsoft.com/en-us/windows/wsl/about
6971
[vscode-link]: https://code.visualstudio.com/

scripts/start-app.sh

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ fi
1414

1515
echo "Starting API (Flask) server..."
1616

17-
python3 -m venv venv
18-
source venv/bin/activate
17+
# Check OS and use appropriate Python command
18+
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
19+
# Windows
20+
py -m venv venv
21+
source venv/Scripts/activate || . venv/Scripts/activate
22+
else
23+
# macOS/Linux
24+
python3 -m venv venv
25+
source venv/bin/activate || . venv/bin/activate
26+
fi
27+
1928
pip install -r server/requirements.txt
2029
cd server || {
2130
echo "Error: server directory not found"
@@ -24,7 +33,13 @@ cd server || {
2433
}
2534
export FLASK_DEBUG=1
2635
export FLASK_PORT=5100
27-
python app.py &
36+
37+
# Use appropriate Python command based on OS
38+
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
39+
py app.py &
40+
else
41+
python3 app.py &
42+
fi
2843

2944
# Store the Python server process ID
3045
SERVER_PID=$!
@@ -53,13 +68,43 @@ echo "Ctl-C to stop the servers"
5368
# Function to handle script termination
5469
cleanup() {
5570
echo "Shutting down servers..."
56-
kill $SERVER_PID
57-
kill $CLIENT_PID
71+
72+
# Kill processes and their child processes
73+
if [[ "$OSTYPE" == "msys" ]] || [[ "$OSTYPE" == "win32" ]]; then
74+
taskkill //F //T //PID $SERVER_PID 2>/dev/null
75+
taskkill //F //T //PID $CLIENT_PID 2>/dev/null
76+
else
77+
# Send SIGTERM first to allow graceful shutdown
78+
kill -TERM $SERVER_PID 2>/dev/null
79+
kill -TERM $CLIENT_PID 2>/dev/null
80+
81+
# Wait briefly for graceful shutdown
82+
sleep 2
83+
84+
# Then force kill if still running
85+
if ps -p $SERVER_PID > /dev/null 2>&1; then
86+
pkill -P $SERVER_PID 2>/dev/null
87+
kill -9 $SERVER_PID 2>/dev/null
88+
fi
89+
90+
if ps -p $CLIENT_PID > /dev/null 2>&1; then
91+
pkill -P $CLIENT_PID 2>/dev/null
92+
kill -9 $CLIENT_PID 2>/dev/null
93+
fi
94+
fi
95+
96+
# Deactivate virtual environment if active
97+
if [[ -n "${VIRTUAL_ENV}" ]]; then
98+
deactivate
99+
fi
100+
101+
# Return to initial directory
102+
cd "$INITIAL_DIR"
58103
exit 0
59104
}
60105

61-
# Trap SIGINT (Ctrl+C) and SIGTERM
62-
trap cleanup SIGINT SIGTERM
106+
# Trap multiple signals
107+
trap cleanup SIGINT SIGTERM SIGQUIT EXIT
63108

64109
# Keep the script running
65110
wait

0 commit comments

Comments
 (0)