File tree Expand file tree Collapse file tree 3 files changed +13
-12
lines changed
frameworks/Python/aiohttp Expand file tree Collapse file tree 3 files changed +13
-12
lines changed Original file line number Diff line number Diff line change 11FROM python:3.13
22
3- RUN apt-get update && apt-get install -y \
4- nginx \
5- netcat-openbsd
3+ RUN apt-get update && apt-get install -y nginx
64
75ADD ./requirements.txt /aiohttp/requirements.txt
86
Original file line number Diff line number Diff line change 77if __name__ == '__main__' :
88 uvloop .install ()
99 parser = argparse .ArgumentParser ()
10- parser .add_argument ('--port ' , type = int , required = True )
10+ parser .add_argument ('--socket ' , type = str , required = True )
1111 args = parser .parse_args ()
1212
1313 app = create_app ()
14- web .run_app (app , port = args .port )
14+ web .run_app (app , path = args .socket )
Original file line number Diff line number Diff line change @@ -4,21 +4,24 @@ CORES=$(nproc)
44echo " $CORES cores detected, starting $CORES aiohttp workers..."
55
66for i in $( seq 0 $(( CORES- 1 )) ) ; do
7- PORT= $(( 8000 + i ))
8- echo " Starting worker on port $PORT "
9- python3 -O -m app.app --port $PORT &
7+ SOCKET= " /run/aiohttp- $i .sock "
8+ echo " Starting worker on socket $SOCKET "
9+ python3 -O -m app.app --socket $SOCKET &
1010done
1111
1212echo " Waiting for all workers to be ready..."
1313for i in $( seq 0 $(( CORES- 1 )) ) ; do
14- PORT= $(( 8000 + i ))
15- until nc -z localhost $PORT ; do
16- echo " Waiting for port $PORT ..."
14+ SOCKET= " /run/aiohttp- $i .sock "
15+ until [ -S " $SOCKET " ] ; do
16+ echo " Waiting for socket $SOCKET ..."
1717 sleep 0.1
1818 done
19+ chown root:www-data " $SOCKET "
20+ chmod 660 " $SOCKET "
1921done
2022
2123cat > /aiohttp/nginx.conf << EOF
24+ user www-data;
2225worker_processes auto;
2326
2427events {
3336EOF
3437
3538for i in $( seq 0 $(( CORES- 1 )) ) ; do
36- echo " server 127.0.0.1: $(( 8000 + i )) ;" >> /aiohttp/nginx.conf
39+ echo " server unix:/run/aiohttp- $i .sock fail_timeout=0 ;" >> /aiohttp/nginx.conf
3740done
3841
3942cat >> /aiohttp/nginx.conf << EOF
You can’t perform that action at this time.
0 commit comments