From 15ada52bfa91218d58e6b6bd7b7030642314dfb4 Mon Sep 17 00:00:00 2001
From: ha7ilm <retzlerandras@gmail.com>
Date: Sun, 30 Nov 2014 12:21:19 +0100
Subject: [PATCH] python2 fix, ctrl+c now exits app, useless javascript console
 message removed

---
 htdocs/openwebrx.js |  3 ++-
 openwebrx.py        | 15 +++++++++++----
 rtl_mus.py          |  8 ++++++++
 3 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/htdocs/openwebrx.js b/htdocs/openwebrx.js
index 381da83..a566fc7 100755
--- a/htdocs/openwebrx.js
+++ b/htdocs/openwebrx.js
@@ -897,7 +897,7 @@ function canvas_mousewheel(evt)
 	//console.log(evt);
 	var relativeX=(evt.offsetX)?evt.offsetX:evt.layerX;
 	var dir=(evt.deltaY/Math.abs(evt.deltaY))>0;
-	console.log(dir);
+	//console.log(dir);
 	//i/=120;
 	/*while (i--)*/ zoom_step(dir, relativeX, zoom_center_where_calc(evt.pageX));
 	evt.preventDefault();	
@@ -1261,6 +1261,7 @@ function on_ws_error(event)
 
 function open_websocket()
 {
+	//ws_url="ws://"+(window.location.origin.split("://")[1])+"/ws/" //guess automatically
 	if (!("WebSocket" in window)) 
 		divlog("Your browser does not support WebSocket, which is required for WebRX to run. Please upgrade to a HTML5 compatible browser.");
 	ws = new WebSocket(ws_url+client_id);
diff --git a/openwebrx.py b/openwebrx.py
index fdb2f5e..61ea335 100755
--- a/openwebrx.py
+++ b/openwebrx.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python2
 print "" # python2.7 is required to run OpenWebRX instead of python3. Please run me by: python2 openwebrx.py
 """
 OpenWebRX: open-source web based SDR for everyone!
@@ -54,6 +54,7 @@ import ctypes
 import rxws
 import uuid
 import config_webrx as cfg
+import signal
 
 def import_all_plugins(directory):
 	for subdir in os.listdir(directory):
@@ -67,10 +68,13 @@ def import_all_plugins(directory):
 class MultiThreadHTTPServer(ThreadingMixIn, HTTPServer):
     pass 
 
+def handle_signal(signal, frame):
+	print "[openwebrx] Ctrl+C: aborting."
+	os._exit(1) #not too graceful exit
+
 def main():
 	global clients
 	global clients_mutex
-
 	print
 	print "OpenWebRX - Open Source Web Based SDR for Everyone  | for license see LICENSE file in the package"
 	print "_________________________________________________________________________________________________"
@@ -78,6 +82,9 @@ def main():
 	print "Author contact info:    Andras Retzler, HA7ILM <randras@sdr.hu>"
 	print 
 
+	#Set signal handler
+	signal.signal(signal.SIGINT, handle_signal) #http://stackoverflow.com/questions/1112343/how-do-i-capture-sigint-in-python
+
 	#Load plugins
 	import_all_plugins("plugins/dsp/")
 
@@ -98,9 +105,9 @@ def main():
 		print "[openwebrx-main] Started rtl thread: "+cfg.start_rtl_command
 
 	#Run rtl_mus.py in a different OS thread
-	rtl_mus_thread=threading.Thread(target = lambda:subprocess.Popen("python rtl_mus.py config_rtl", shell=True), args=())
+	rtl_mus_thread=threading.Thread(target = lambda:subprocess.Popen("python2 rtl_mus.py config_rtl", shell=True), args=())
 	rtl_mus_thread.start() # The new feature in GNU Radio 3.7: top_block() locks up ALL python threads until it gets the TCP connection.
-	print "[openwebrx-main] Started rtl_mus"
+	print "[openwebrx-main] Started rtl_mus."
 	time.sleep(1) #wait until it really starts	
 
 	#Initialize clients
diff --git a/rtl_mus.py b/rtl_mus.py
index b348961..8210b36 100644
--- a/rtl_mus.py
+++ b/rtl_mus.py
@@ -37,10 +37,15 @@ import pdb
 import asyncore
 import multiprocessing
 import dl
+import signal
 
 import code
 import traceback
 
+def handle_signal(signal, frame):
+	log.info("Ctrl+C: aborting.")
+	os._exit(1) #not too graceful exit
+
 def ip_match(this,ip_ranges,for_allow):
 	if not len(ip_ranges):
 		return 1 #empty list matches all ip addresses
@@ -445,6 +450,9 @@ def main():
 	global rtl_tcp_core
 	global sample_rate
 
+	#Set signal handler
+	signal.signal(signal.SIGINT, handle_signal) #http://stackoverflow.com/questions/1112343/how-do-i-capture-sigint-in-python
+
 	# set up logging
 	log = logging.getLogger("rtl_mus")
 	log.setLevel(logging.DEBUG)
-- 
GitLab