Skip to content

Commit

Permalink
Makes sure all cores are shut down on turn off
Browse files Browse the repository at this point in the history
  • Loading branch information
AriAlavi committed Sep 1, 2020
1 parent d9cc41d commit b4952be
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 34 deletions.
11 changes: 9 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@

SERVER_KILL = None
USERS_CONNECTED = None
SERVER_PROCESS = None

@eel.expose
def hostServer(server_ip):
global hosting
global SERVER_KILL
global USERS_CONNECTED
global SERVER_PROCESS
try:
# server(server_ip, 5003)
p = multiprocessing.Process(target=server, args=(server_ip, 5003, SERVER_KILL, USERS_CONNECTED))
SERVER_PROCESS = multiprocessing.Process(target=server, args=(server_ip, 5003, SERVER_KILL, USERS_CONNECTED))
hosting = True
p.start()
SERVER_PROCESS.start()
return True
except Exception as e:
print(e)
Expand Down Expand Up @@ -91,6 +93,7 @@ def main():
global hosting
global SERVER_KILL
global USERS_CONNECTED
global SERVER_PROCESS
print("Starting setup...")
hosting = False
setup()
Expand Down Expand Up @@ -125,6 +128,10 @@ def main():
"function" : "stop",
"args" : ()
})
if SERVER_PROCESS:
SERVER_PROCESS.kill()
p.kill()
print("Execution complete")

if __name__ == "__main__":
main()
33 changes: 1 addition & 32 deletions network.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ async def run(self, host_ip, port, kill, USER_COUNT):
while self.interrupt.empty():
await asyncio.sleep(0)
server_task.cancel()
user_count_task.cancel()
print("Shutting down server...")
sys.exit(1)

Expand Down Expand Up @@ -391,38 +392,6 @@ def requestFileSize(self, file_name):
s.send(b"\x02")
self.sendStr(s, file_name)
return self.recvInt(s)


def yesNoValidator(obj):
if obj in ["y", "n"]:
return True
return False

def validateIP(givenIp):
if re.match(r"^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$",givenIp):
return True
return False



def menu(prompt, validator, useClipboard=False):
import pyperclip
if useClipboard:
input(prompt)
result = pyperclip.paste()
else:
result = input(prompt + "\n")
while not validator(result):
if useClipboard:
print("{} is invalid".format(pyperclip.paste()))
else:
print("Invalid input!")
if useClipboard:
input(prompt)
result = pyperclip.paste()
else:
result = input(prompt + "\n")
return result


def server(host_ip, port, kill, USER_COUNT):
Expand Down

0 comments on commit b4952be

Please sign in to comment.