From cd3ff41005bb4c7024c9083ea75872730c12bac8 Mon Sep 17 00:00:00 2001 From: ha7ilm Date: Thu, 18 Dec 2014 12:13:27 +0100 Subject: [PATCH] experimental pypy compatibility (tested with PyPy 2.2.1) --- openwebrx.py | 18 ++++++++++++++---- rtl_mus.py | 17 +++++++++++------ 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/openwebrx.py b/openwebrx.py index 08b958b..37e09e4 100755 --- a/openwebrx.py +++ b/openwebrx.py @@ -43,7 +43,6 @@ import time import md5 import random import threading -import dl import sys import traceback from collections import namedtuple @@ -56,6 +55,14 @@ import uuid import config_webrx as cfg import signal +#pypy compatibility +try: import dl +except: pass +try: import __pypy__ +except: pass +pypy="__pypy__" in globals() + + def import_all_plugins(directory): for subdir in os.listdir(directory): if os.path.isdir(directory+subdir) and not subdir[0]=="_": @@ -73,8 +80,7 @@ def handle_signal(signal, frame): os._exit(1) #not too graceful exit def main(): - global clients - global clients_mutex + global clients, clients_mutex, pypy print print "OpenWebRX - Open Source Web Based SDR for Everyone | for license see LICENSE file in the package" print "_________________________________________________________________________________________________" @@ -88,6 +94,9 @@ def main(): #Load plugins import_all_plugins("plugins/dsp/") + #Pypy + if pypy: print "pypy detected (and now something completely different: a c code is expected to run at a speed of 3*10^8 m/s?)" + #Change process name to "openwebrx" (to be seen in ps) try: for libcpath in ["/lib/i386-linux-gnu/libc.so.6","/lib/libc.so.6"]: @@ -105,7 +114,8 @@ 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("python2 rtl_mus.py config_rtl", shell=True), args=()) + python_command="pypy" if pypy else "python2" + rtl_mus_thread=threading.Thread(target = lambda:subprocess.Popen(python_command+" 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." time.sleep(1) #wait until it really starts diff --git a/rtl_mus.py b/rtl_mus.py index 8210b36..c244380 100644 --- a/rtl_mus.py +++ b/rtl_mus.py @@ -36,8 +36,10 @@ import thread import pdb import asyncore import multiprocessing -import dl import signal +#pypy compatiblity +try: import dl +except: pass import code import traceback @@ -504,11 +506,14 @@ if __name__=="__main__": print " distributed under GNU GPL v3" print - for libcpath in ["/lib/i386-linux-gnu/libc.so.6","/lib/libc.so.6"]: - if os.path.exists(libcpath): - libc = dl.open(libcpath) - libc.call("prctl", 15, "rtl_mus", 0, 0, 0) - break + try: + for libcpath in ["/lib/i386-linux-gnu/libc.so.6","/lib/libc.so.6"]: + if os.path.exists(libcpath): + libc = dl.open(libcpath) + libc.call("prctl", 15, "rtl_mus", 0, 0, 0) + break + except: + pass # === Load configuration script === if len(sys.argv)==1: