process_thread_action
import psycopg2
import threading conn_fmac = psycopg2.connect(database='filter_useless_mac', user='user', password='password', host='192.168.168.168',
port='5432') def fetch_rows(f_l):
r = {}
with conn_fmac:
with conn_fmac.cursor() as curs:
for i in f_l:
# http://initd.org/psycopg/docs/faq.html
# The arguments in the execute() methods can only represent data to pass to the query: they cannot represent a table or field name:
curs.execute('SELECT detail_data FROM apiv2_single_mac_with_res WHERE mac= %s LIMIT 1 ', (i,)) # psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block
try:
t = curs.fetchone()
if t is not None:
r[i] = {}
r[i] = t[0]
except Exception:
continue
return r def update_rows(id, new_val):
with conn_fmac:
with conn_fmac.cursor() as curs:
try:
curs.execute(
'UPDATE control_group_with_compute_res SET mac_with_res_position_lat_lon_unique_num=%s WHERE oid_timestamp=%s',
(new_val, id))
print(threading.get_ident(), 'OK')
except Exception:
print(Exception) class MyThread(threading.Thread):
def __init__(self, func, args, name):
threading.Thread.__init__(self)
self.name, self.func, self.args = name, func, args def run(self):
self.func(self.args) def main():
with conn_fmac:
with conn_fmac.cursor() as curs:
curs.execute(
'SELECT oid_timestamp,mac_with_res_position FROM control_group_with_compute_res WHERE mac_with_res_position IS NOT NULL ORDER BY oid_timestamp DESC ')
tuple_l = curs.fetchall() tn, tl, tstep = len(tuple_l), [], 200 def tf(ts):
print(ts)
te = ts + tstep
te = min(te, tn)
for i in tuple_l[ts:te]:
oid_timestamp, mac_with_res_position = i
n_l = []
for k in mac_with_res_position:
longitude, latitude = mac_with_res_position[k]['longitude'], mac_with_res_position[k]['latitude']
s = '%s%s' % (longitude, latitude)
if s not in n_l:
n_l.append(s)
n = len(n_l)
if n > 0:
update_rows(oid_timestamp, n) for i in range(0, tn, tstep):
if i >= tn:
break
thread_instance = MyThread(tf, (i), tf.__name__)
tl.append(thread_instance) for t in tl:
t.setDaemon = False
t.start()
for t in tl:
t.join() if __name__ == '__main__':
main()
import json
import psycopg2
import threading conn_fmac = psycopg2.connect(database='filter_useless_mac', user='postgres', password='postgres', host='192.168.8.8',
port='5432') def update_rows(id, new_val):
with conn_fmac:
with conn_fmac.cursor() as curs:
try:
curs.execute(
'UPDATE control_group_with_compute_res SET add_lat_lon_to_original_res=%s WHERE oid_timestamp=%s',
(new_val, id))
print(threading.get_ident(), 'OK')
except Exception:
print(Exception) class MyThread(threading.Thread):
def __init__(self, func, args, name):
threading.Thread.__init__(self)
self.name, self.func, self.args = name, func, args def run(self):
self.func(self.args) def main():
with conn_fmac:
with conn_fmac.cursor() as curs:
sql = "SELECT tmp.oid_timestamp, ja.latitude, ja.longitude FROM ( SELECT oid_timestamp, detail_data ->> 'area_code' AS area_code FROM control_group_with_compute_res) tmp LEFT JOIN jmtool_areacode_longitude_latitude ja ON tmp.area_code = ja.area_code WHERE ja.area_code IS NOT NULL ORDER BY oid_timestamp ASC;"
curs.execute(sql)
tuple_l = curs.fetchall() tn, tl, tstep = len(tuple_l), [], 200 def tf(ts):
print(ts)
te = ts + tstep
te = min(te, tn)
for i in tuple_l[ts:te]:
oid_timestamp, lat, lon = i
r = {}
r['from'], r['latitude'], r['longitude'] = 'jmtool_areacode', lat, lon
update_rows(oid_timestamp, json.dumps(r, ensure_ascii=False)) for i in range(0, tn, tstep):
if i >= tn:
break
thread_instance = MyThread(tf, (i), tf.__name__)
tl.append(thread_instance) for t in tl:
t.setDaemon = False
t.start()
for t in tl:
t.join() if __name__ == '__main__':
main()
process_thread_action的更多相关文章
随机推荐
- POJ3086 Treats for the Cows(区间DP)
题目链接 Treats for the Cows 直接区间DP就好了,用记忆化搜索是很方便的. #include <cstdio> #include <cstring> #i ...
- 提升开发效率的一款mybatis开发神器
文末附有完整案例的代码内容!! 以前在开发的时候,使用mybatis的时候,经常都需要先配置xml映射文件,然后每条sql操作都需要自己进行手动编写,对于一些复杂的sql这么来操作确实有必要,但是如果 ...
- loj #100. 矩阵乘法
题目描述 这是一道模板题. 分别给定 n×p n \times pn×p 和 p×m p \times mp×m 的两个矩阵 A AA 和 B BB,求 A×B A \times BA×B. 输入格式 ...
- Meet Dgraph — an open source, scalable, distributed, highly available and fast graph databas
https://dgraph.io/ Meet Dgraph — an open source, scalable, distributed, highly available and fast gr ...
- dedecms调用新闻文章列表
效果如下: 代码如下: <div class="list"> <ul class="d6 ico4"> {dede:list pages ...
- 报错:LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 1>
这段时间忙于看文献,没用过VS了. 今天用着用着就报错了: LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏 1> 问度娘,大神给出了解决方法 ...
- 【重点突破】——第三方绘图工具FusionCharts.js的使用详解
一.引言 项目组中,经常会因为绘制图表的繁杂度,衡量会不会使用第三方绘图工具,如果自己做很困难,成本使用高于第三方绘图工具库,就会使用.很多人使用的是Chart.js,因为它是免费使用的,不过,缺点就 ...
- HTML5 Canvas 绘制佛教万字
代码如下: <!DOCTYPE html> <html lang="utf-8"> <meta http-equiv="Content-Ty ...
- js执行顺序总结
参考博文:http://www.2cto.com/kf/201401/273825.html http://www.jb51.net/article/44123.htm http://zhidao.b ...
- SVN 服务端、客户端安装及配置、导入导出项目
http://blog.csdn.net/xcy13638760/article/details/12994923 http://www.cnblogs.com/armyfai/p/3985660.h ...