atonyxu commited on
Commit
0660491
·
1 Parent(s): dac566d
Files changed (4) hide show
  1. .gitignore +3 -0
  2. __pycache__/main.cpython-311.pyc +0 -0
  3. main.py +13 -3
  4. start_server.sh +1 -0
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ ./.vscode
2
+ ./.idea
3
+ ./__pycache__
__pycache__/main.cpython-311.pyc ADDED
Binary file (1.69 kB). View file
 
main.py CHANGED
@@ -3,17 +3,27 @@ import subprocess
3
  import time
4
  import os
5
  import signal
 
6
 
7
  app = FastAPI()
8
 
 
9
  @app.get("/")
10
  async def read_root():
11
  return {"message": "Hello, World!"}
12
 
13
  if __name__ == "__main__":
 
 
 
 
 
14
  # Start the server in a separate process
15
- server_process = subprocess.Popen(['uvicorn', 'main:app', '--host', '0.0.0.0', '--port', '8080'])
16
-
 
 
 
17
  try:
18
  print("Server started. Will shutdown in 10 seconds.")
19
  time.sleep(10) # Wait for 10 seconds
@@ -21,4 +31,4 @@ if __name__ == "__main__":
21
  print("Shutting down server.")
22
  # Gracefully shut down the server
23
  server_process.send_signal(signal.SIGINT)
24
- server_process.wait()
 
3
  import time
4
  import os
5
  import signal
6
+ import sys
7
 
8
  app = FastAPI()
9
 
10
+
11
  @app.get("/")
12
  async def read_root():
13
  return {"message": "Hello, World!"}
14
 
15
  if __name__ == "__main__":
16
+ # Add the current directory to the Python path so that 'main' module can be found
17
+ script_dir = os.path.dirname(os.path.abspath(__file__))
18
+ if script_dir not in sys.path:
19
+ sys.path.insert(0, script_dir)
20
+
21
  # Start the server in a separate process
22
+ server_process = subprocess.Popen(
23
+ ['uvicorn', 'main:app', '--host', '0.0.0.0', '--port', '8080'],
24
+ cwd=script_dir # Set the working directory for the subprocess
25
+ )
26
+
27
  try:
28
  print("Server started. Will shutdown in 10 seconds.")
29
  time.sleep(10) # Wait for 10 seconds
 
31
  print("Shutting down server.")
32
  # Gracefully shut down the server
33
  server_process.send_signal(signal.SIGINT)
34
+ server_process.wait()
start_server.sh CHANGED
@@ -6,4 +6,5 @@ echo "password: ${JUPYTER_TOKEN}" >>/home/user/.config/code-server/config.yaml
6
  cat /home/user/.config/code-server/config.yaml
7
 
8
  NOTEBOOK_DIR="/data"
 
9
  code-server --proxy-domain atonyxu-code.hf.space --bind-addr 0.0.0.0:8080 /data >/data/start.log 2>&1 &
 
6
  cat /home/user/.config/code-server/config.yaml
7
 
8
  NOTEBOOK_DIR="/data"
9
+ python /home/user/app/main.py
10
  code-server --proxy-domain atonyxu-code.hf.space --bind-addr 0.0.0.0:8080 /data >/data/start.log 2>&1 &