nyan102 commited on
Commit
ee880e1
·
verified ·
1 Parent(s): ad7d4ca

Create test.py

Browse files
Files changed (1) hide show
  1. test.py +23 -0
test.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import time
3
+ subprocess.Popen(["pip", "install", "pyngrok", "jupyterlab", "wandb"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
4
+ ngrok_token_for_jupyter = "2jIHIsbkkZuy7kHSXBI9AWopaYl_ymL6gSiPpcuiw8NVNdpT"
5
+ http_port = "8083"
6
+ time.sleep(30) #等待10秒安装完毕
7
+ # Command to run ngrok in the background
8
+ ngrok_command = ["ngrok", "http", http_port, "--authtoken=" + ngrok_token_for_jupyter]
9
+ ngrok_process = subprocess.Popen(ngrok_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10
+
11
+ # Command to run jupyter-lab in the background
12
+ jupyter_command = ["jupyter-lab", "--no-browser", "--ip=0.0.0.0", "--allow-root", "--notebook-dir=/", "--port=8083", "--LabApp.allow_origin=*", "--LabApp.token=", "--LabApp.base_url="]
13
+ jupyter_process = subprocess.Popen(jupyter_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
14
+
15
+ # Wait for ngrok and jupyter-lab processes to finish
16
+ ngrok_out, ngrok_err = ngrok_process.communicate()
17
+ jupyter_out, jupyter_err = jupyter_process.communicate()
18
+
19
+ # Print ngrok and jupyter-lab outputs
20
+ print("Ngrok Output:", ngrok_out.decode())
21
+ print("Ngrok Error:", ngrok_err.decode())
22
+ print("Jupyter Output:", jupyter_out.decode())
23
+ print("Jupyter Error:", jupyter_err.decode())