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的更多相关文章

随机推荐

  1. Oracle 安装前准备

    [root@localhost Desktop]# groupadd -g 110 oinstall 用来安装oracle软件 [root@localhost Desktop]# groupadd - ...

  2. Storyboards Tutorial 01

    Storyboarding 是在ios 5时候引进入的一个非常出色的特性.节省了为app创建user interfaces的时间.

  3. 了解什么是WebLogic Server 多数据源(Multi-DataSource)

      1. 什么是多数据源 我们知道配置WebLogic Server集群时一定要配置一个单一接入点(例如:Apache或F5),这样客户端只要访问这个单一入口点就可以了.对于客户来说,就好象访问一台服 ...

  4. VS2010 MFC中 在FormView派生类里获取文档类指针的方法

    经过苦苦调试,今晚终于解决了一个大问题. 我想要实现的是:在一个FormView的派生类里获取到文档类的指针. 但是出现问题:试了很多办法,始终无法获取到. 终于,此问题在我不懈地调试加尝试下解决了. ...

  5. JS: document.getElementBy(), setInerval()

    ylbtech-JavaScript-DOM document.getElementBy(),setInerval() 1.A,document.getElementBy()返回顶部 document ...

  6. Windows API 教程(七) hook 钩子监听

    茵蒂克丝 如何创建一个窗口 手动创建窗口的流程 实际代码 安装钩子 (Install hook) 钩子简介 SetWindowsHookEx 函数 设置监听[键盘]消息 设置监听[鼠标]消息 如何创建 ...

  7. Jboss7类载入器

    1. 类载入器理论知识介绍 类载入器基于Jboss Module,代替了层次类载入环境,避免了当类存在多个版本号时,导致类载入错误. 类载入是基于模块的.必须显示的定义模块依赖.部署也是模块化的,假设 ...

  8. 【前端GUI】—— 网站美工必须掌握的PS知识点&思维导图

    前言:前端离不开与设计的沟通,有时候还需要自己上手改动甚至设计网页,所以这里简单梳理一下近期学习的“网站美工”相关知识及练习.(工作用不上的时候,自己玩儿着也蛮有意思的,哈哈(*゚∀゚*)~) 一.P ...

  9. 给交换机端口设ip

    先给端口设vlan,再给vlan设ip [H3C]vlan [H3C-vlan100]port GigabitEthernet // <H3C>sy System View: return ...

  10. Shell脚本之:case

    case ... esac 与其他语言中的 switch ... case 语句类似,是一种多分枝选择结构. case语句的语法 case 值 in 模式1) command1 command2 co ...