Skip to content

Commit 9909a16

Browse files
committed
asyncronous watch
1 parent 3d2acbf commit 9909a16

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

ide/deploy/client.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from pathlib import Path
1919
import os, os.path, json
2020
from subprocess import Popen
21+
import asyncio
2122

2223
def get_nuvolaris_config(key):
2324
try:
@@ -29,12 +30,18 @@ def get_nuvolaris_config(key):
2930
return None
3031

3132
# serve web area
32-
def serve():
33+
async def serve():
3334
devel = get_nuvolaris_config("devel")
3435
if devel is None:
3536
devel = "nuv ide serve"
3637
print(devel)
37-
Popen(devel, shell=True, cwd=os.environ.get("NUV_PWD"), env=os.environ)
38+
#Popen(devel, shell=True, cwd=os.environ.get("NUV_PWD"), env=os.environ)
39+
pwd = os.environ.get("NUV_PWD")
40+
cmd = f"cd '{pwd}' ; {devel}"
41+
proc = await asyncio.create_subprocess_shell(cmd,
42+
stdin=asyncio.subprocess.PIPE,
43+
stdout=asyncio.subprocess.PIPE,
44+
stderr=asyncio.subprocess.PIPE)
3845

3946
# build
4047
def build():

ide/deploy/watch.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,17 @@ async def redeploy():
4141

4242
def watch():
4343
loop = asyncio.get_event_loop()
44-
#task = loop.create_task(redeploy())
45-
task = asyncio.ensure_future(redeploy())
44+
task1 = loop.create_task(redeploy())
45+
#task = asyncio.ensure_future(redeploy())
46+
task2 = loop.create_task(serve())
4647
def end_loop():
4748
print("Ending task.")
48-
task.cancel()
49+
task1.cancel()
50+
task2.cancel()
4951
loop.add_signal_handler(signal.SIGTERM, end_loop)
5052

5153
try:
52-
loop.run_until_complete(task)
54+
loop.run_until_complete(task1)
5355
except asyncio.CancelledError:
5456
pass
5557
finally:

0 commit comments

Comments
 (0)