Skip to content

Commit

Permalink
WIP: Handle CTRL+C, and exit code
Browse files Browse the repository at this point in the history
  • Loading branch information
terencode committed May 3, 2020
1 parent 7ab8b05 commit 5985a24
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions joycond-cemuhook.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#! /usr/bin/env python3

import signal
import sys
import evdev
from threading import Thread
Expand Down Expand Up @@ -457,6 +458,8 @@ def handle_devices(self):

print("Looking for Nintendo Switch controllers...")

exception = None

while True:
try:
evdev_devices = [evdev.InputDevice(path) for path in evdev.list_devices()]
Expand Down Expand Up @@ -496,8 +499,9 @@ def handle_devices(self):
self.print_slots()

time.sleep(0.2) # sleep for 0.2 seconds
except:
pass

except Exception as e:
exception = e

def print_slots(self):
slots_print = []
Expand Down Expand Up @@ -533,6 +537,22 @@ def start(self):

self.device_thread.join()

def stop(self, sig=None, frame=None, err=None):
if sig is not None:
print("Stopping server")
self.report_clean(self)
self.disconnected = True
asyncio.get_event_loop().close()
return err




server = UDPServer('127.0.0.1', 26760)
server.start()

# Handle CTRL+C and systemctl stop default signal
signal.signal(signal.SIGINT, server.stop)
signal.signal(signal.SIGTERM, server.stop)


sys.exit(server.start())

0 comments on commit 5985a24

Please sign in to comment.