Explorar o código

主线程等待子线程结束

peng hai 1 ano
pai
achega
169fe411eb
Modificáronse 1 ficheiros con 6 adicións e 3 borrados
  1. 6 3
      Controller/Cron/CronTaskController.py

+ 6 - 3
Controller/Cron/CronTaskController.py

@@ -1301,7 +1301,8 @@ class CronComparedDataView(View):
             order_list = PayPalService(PAYPAL_CRD['client_id'], PAYPAL_CRD['client_secret']).get_transactions(data)
             thread = threading.Thread(target=CronComparedDataView.thread_compared_paypal_order,
                                       args=(order_list['transaction_details'], end_date))
-            thread.start()
+            thread.start()  # 启动线程
+            thread.join()  # 主线程等待子线程结束
             return response.json(0)
         except Exception as e:
             LOGGER.info('CronComparedDataView.compared_paypal_order, errLine:{}, errMsg:{}'.format(
@@ -1377,7 +1378,6 @@ class CronComparedDataView(View):
                                                order_ids=order_ids, creat_time=now_time, upd_time=now_time)
         LOGGER.info('paypal每日对账结束时间:{}'.format(int(time.time())))
 
-
     @staticmethod
     def compared_wechat_order(response):
         today = datetime.datetime.today()
@@ -1388,6 +1388,7 @@ class CronComparedDataView(View):
             thread = threading.Thread(target=CronComparedDataView.thread_compared_wechat_order,
                                       args=(order_list,))
             thread.start()
+            thread.join()  # 主线程等待子线程结束
             return response.json(0)
         except Exception as e:
             LOGGER.info('CronComparedDataView.compared_wechat_order, errLine:{}, errMsg:{}'.format(
@@ -1447,6 +1448,7 @@ class CronComparedDataView(View):
             thread = threading.Thread(target=CronComparedDataView.thread_compared_alipay_order,
                                       args=(order_list,))
             thread.start()
+            thread.join()  # 主线程等待子线程结束
             return response.json(0)
         except Exception as e:
             LOGGER.info('CronComparedDataView.compared_alipay_order, errLine:{}, errMsg:{}'.format(
@@ -1495,7 +1497,8 @@ class CronComparedDataView(View):
                 return response.json(0, list(order_qs))
             thread = threading.Thread(target=CronComparedDataView.thread_compared_ansjer_order,
                                       args=(list(order_qs), start_date))
-            thread.start()
+            thread.start()  # 启动线程
+            thread.join()  # 主线程等待子线程结束
             return response.json(0)
         except Exception as e:
             LOGGER.info('CronComparedDataView.compared_ansjer_order, errLine:{}, errMsg:{}'.format(