chanjunkai пре 5 година
родитељ
комит
34d19c2813
1 измењених фајлова са 20 додато и 3 уклоњено
  1. 20 3
      controller/index.py

+ 20 - 3
controller/index.py

@@ -24,6 +24,7 @@ from model.models import UserModel, UidRtspModel
 from object.tkObject import tkObject
 from service.CommonService import CommonService
 from object.RedisObject import RedisObject
+import _thread
 
 SERVER_PREFIX = 'http://www.dvema.com'
 
@@ -154,6 +155,23 @@ class oa2TokenView(TemplateView):
             return JsonResponse(res_json)
 
 
+import threading
+
+
+def runSendRtspMsg_thread(UID, PWD, MSG):
+    command = "./pushtool {UID} {PWD} {MSG} 1".format(UID=UID, PWD=PWD, MSG=MSG)
+    print('command=>{command}'.format(command=command))
+    try:
+        back = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate(
+            timeout=10)
+    except Exception as e:
+        return False
+    else:
+        print("back0----", back[0].decode())  # 注意需要进行解码操作,默认输出的是字节
+        print("back1----", back[1].decode())  # back是一个元祖,可以通过元祖取值的方式获取结果
+        return True
+
+
 class oa2RtspStartView(TemplateView):
     def post(self, request, *args, **kwargs):
         request.encoding = 'utf-8'
@@ -204,7 +222,7 @@ class oa2RtspStartView(TemplateView):
                     return JsonResponse({'msg': 'stop yes', 'code': 0})
                 else:
                     return JsonResponse({'msg': 'stop no', 'code': 0})
-            send_flag = self.runSendRtspMsg(UID, PWD, MSG)
+            threading.Thread(target=runSendRtspMsg_thread, args=(UID, PWD, MSG)).start()
             res_json = {
                 'endpointId': id,
                 'manufacturerName': 'Axis',
@@ -220,8 +238,7 @@ class oa2RtspStartView(TemplateView):
                 'authorizationTypes': ['NONE'],
                 'uri': 'rtsp://rtsp.zositech.xyz:443/{stream_name}'.format(stream_name=ur_qs[0]['rtsp_url'])
             }
-            if send_flag:
-                redisObj.set_data(key=key, val=str(res_json), expire=30)
+            redisObj.set_data(key=key, val=str(res_json), expire=30)
             return JsonResponse(res_json, safe=False)
         else:
             return JsonResponse({'msg': 'wrong'})