Skip to content

Commit

Permalink
Support python 2 and python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelDudley committed Dec 7, 2017
1 parent 8a93ca8 commit afe1d92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
16 changes: 10 additions & 6 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@
Samuel Dudley
Jan 2016
'''
import os, json, time, sys, uuid, urllib2
import os, json, time, sys, uuid

from MAVProxy.modules.lib import mp_module
from MAVProxy.modules.lib import mp_settings

from pymavlink import mavutil
import threading, Queue
import threading
try:
import Queue as queue
except ImportError:
import queue

from app import cesium_web_server # the tornado web server
from MAVProxy.modules.mavproxy_cesium.app import cesium_web_server # the tornado web server

import webbrowser # open url's in browser window

from app.config import Configuration
from MAVProxy.modules.mavproxy_cesium.app.config import Configuration


class CesiumModule(mp_module.MPModule):
Expand All @@ -33,7 +37,7 @@ def __init__(self, mpstate, **kwargs):
self.config = Configuration(configuration_path)
self.main_counter = 0

self.message_queue = Queue.Queue()
self.message_queue = queue.Queue()

self.wp_change_time = 0
self.fence_change_time = 0
Expand Down Expand Up @@ -195,7 +199,7 @@ def idle_task(self):
while not self.message_queue.empty():
payload = self.message_queue.get_nowait()
if self.cesium_settings.debug:
print payload
print(payload)

if 'new_connection' in payload.keys():
self.send_defines(target=payload['new_connection'])
Expand Down
15 changes: 9 additions & 6 deletions app/cesium_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import tornado.httpserver
import logging

import os, json, sys, select, signal
import Queue, threading
import os, json, sys, select, signal, threading
try:
import Queue as queue
except ImportError:
import queue

lock = threading.Lock()
live_web_sockets = set()
Expand Down Expand Up @@ -69,7 +72,7 @@ def on_message(self, message):
self.callback(message) # this sends it to the module.send_out_queue_data for further processing.
else:
print("no callback for message: {0}".format(message))
print dir(self)
print(dir(self))

def on_close(self):
if self.configuration.APP_DEBUG:
Expand Down Expand Up @@ -162,7 +165,7 @@ def __init__(self, optsargs):
self.config = Configuration(self.opts.configuration)
signal.signal(signal.SIGINT, self.exit_gracefully)
signal.signal(signal.SIGTERM, self.exit_gracefully)
self.message_queue = Queue.Queue(maxsize=10) # limit queue object count to 10
self.message_queue = queue.Queue(maxsize=10) # limit queue object count to 10
self.pos_target = {}
self.data_stream = ['NAV_CONTROLLER_OUTPUT', 'VFR_HUD',
'ATTITUDE', 'GLOBAL_POSITION_INT',
Expand All @@ -182,7 +185,7 @@ def callback(self, data):
'''callback for data coming in from a websocket'''
try:
self.message_queue.put_nowait(data)
except Queue.Full:
except queue.Full:
print ('Queue full, client data is unable to be enqueued')

def send_data(self, data, target = None):
Expand All @@ -196,7 +199,7 @@ def drain_message_queue(self):
while not self.message_queue.empty():
try:
data = self.message_queue.get_nowait()
except Queue.Empty:
except queue.Empty:
return
else:
# TODO: handle the user feedback
Expand Down

0 comments on commit afe1d92

Please sign in to comment.