multiprocessing django model database -


my database in implementation of script, database has lost data, may more or less, there lot of empty data. thank following list of configuration information: sqlite3 django1.9.8 python 2.7.6

def flush_price():     logging.error("sub-process(es) begin.")     logging.error(int(time.time()))     key = '2500_wine_info.xlsx'     lists = import_excel(key)     lwin11s = []     item in lists:         lwin11s.append(str(item['lwin11'])[:11])     contracts = contract.objects.filter(         is_del=false,         wine__lwin11__in=lwin11s     )     lwins = []     contract in contracts:         lwins.append(str(contract.wine.lwin))     new_arrs = arr_split(lwins, 50)     = conversion_reduce_8_time()     index in range(1, 3641):         date_now = (now - datetime.timedelta(days=index)).strftime('%y-%m-%d')         pool = multiprocessing.pool(processes=len(new_arrs))         new_arr in new_arrs:             pool.apply_async(request_price, (new_arr, date_now, ))         pool.close()         pool.join()         break     logging.error(int(time.time()))     logging.error("sub-process(es) done.")   def request_price(new_arr, date_now):     headers = {         'client_key': client_key,         'client_secret': client_secret,         'accept': 'application/json',         'content-type': 'application/json',     }     data = {         'lwin': new_arr,         'pricetype': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k'],         "currency": "eur",         "pricedate": date_now,     }     price_obj = download_page(vinex_price_api, request_type=1, data=json.dumps(data), headers=headers)     if price_obj.status_code == 200:         price_obj = price_obj.json()         if price_obj['httpcode'] == '200':             lwin_details = price_obj['lwindetail']             lwin_detail in lwin_details:                 # 取得参数                 lwin = lwin_detail['lwin']                 # 取得对象信息                 contract = contract.objects.filter(is_del=false, wine__lwin=lwin).first()                 wine = contract.wine                 # 设置历史数据更新                 redwinepricedata.objects.filter(                     is_del=false,                     contract=contract,                     lwin=lwin,                 ).first()                 redwinepricedata = redwinepricedata()                 redwinepricedata.contract = contract                 redwinepricedata.lwin = lwin                 # 改变数据                 redwinepricedata.pricedate = format_time(detail['pricedate'])                 redwinepricedata.save()                 redwinepricedata.created = add_conversion_8_time(date_now)                 redwinepricedata.save() 

change database information before; the changed database information

pool.apply_async is python's built-in apply, except call returns instead of waiting result. an applyresult object returned. call its get() method retrieve result of function call. the get() method blocks until function completed. thus, pool.apply(func, args, kwargs) is equivalent to pool.apply_async(func, args, kwargs).get().


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -