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的更多相关文章
随机推荐
- Hadoop OutputFormat浅析
问题:reduce输出时,如果不是推测任务写结果时会先写临时目录最后移动到输出目录吗? 下面部分转自Hadoop官网说明 OutputFormat 描述Map/Reduce作业的输出样式. Map/R ...
- JAVA基础之集合、Iterator迭代器、泛型及增强for循环
个人理解: 对于集合,首先要明确的是最顶层的接口是Collection接口类,其包含一些基本的方法以便子类调用,不过在定义的时候最好定义好数据类型,以免遍历时还得必须进行向上转型:特别注意的是其没有关 ...
- 记录一次eclipse的错误:“server tomcat v7.0 server at localhost was unable to start within 45 seconds”的问题解决思路
如果配到上述问题,可以参考网上查找的方法,如下: http://stackoverflow.com/questions/6468520/server-tomcat-v6-0-server-at-loc ...
- ARM Linux系统调用的原理
转载自:http://blog.csdn.net/hongjiujing/article/details/6831192 ARM Linux系统调用的原理 操作系统为在用户态运行的进程与硬件设备进行交 ...
- Oracle 11gR2 RAC 单网卡 转 双网卡绑定 配置步骤
之前写过一篇双网卡绑定的文章,如下: Oracle RAC 与 网卡绑定 http://blog.csdn.net/tianlesoftware/article/details/6189639 Ora ...
- 判断vps类型
- Fresco对Listview等快速滑动时停止加载
Fresco中在listview之类的快速滑动时停止加载,滑动停止后恢复加载: 1.设置图片请求是否开启 // 暂停图片请求 public static void imagePause() { Fre ...
- 2016.10.17 yaml文件里的labels和Pod、RC、Service的对应关系
在看kubernetes的例子时,出现了一个疑问. Pod.RC.Service的yaml文件里,都出现了labels,还有labelSelector.有些不太清楚,因此就这点来学习下. 接上文: ...
- 安卓获取软硬件信息并上传给server(Socket实现)
首先,项目结构如图--A:分为client部分CheckInfo和server端CheckInfo_Server.CheckInfo获取手机信息(Mac,Cpu,内存,已安装软件信息等)并上传到ser ...
- codeforces 204(Div.1 A) Little Elephant and Interval(贪心)
题意: 有一种个位数与最高位数字相等的数字,求在l,r的范围内,这样的数字的个数. 思路: 找下规律就知道当当n>10的时候除去个位以后的答案等于n/10,然后考虑第一个数字是否小于最后一个.小 ...