Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/local/bin/python
- import os
- import psycopg2
- import sys
- import time
- import datetime
- ts = time.time()
- amount = 250
- process = 25
- def child(from_id, to_id):
- print ("\nChild start", os.getpid())
- print datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
- try:
- con = psycopg2.connect(host='ohm.f4.htw-berlin.de', port='5432', database='ohdm', user='mholst', password='master85')
- cur = con.cursor()
- cur.execute("SELECT lg.id, lg.multilinestring_geom, gd.valid_since, gd.valid_since, gt.key, gt.value FROM ohdm.multilinestring_geom lg JOIN ohdm.geographic_geom_dates gd ON gd.id_multilinestring_geom = lg.id JOIN ohdm.geographic_objects gobjects ON gobjects.id = gd.id_geographic_object_source JOIN ohdm.geographic_tag gt ON gt.id_geographic_objects = gobjects.id WHERE lg.id >= %s AND lg.id <= %s",(from_id, to_id))
- result = cur.fetchall()
- for r in result:
- #cur.execute("INSERT INTO ohdm.rendering_line_mholst (multilinestring_geom, valid_since, valid_until) VALUES (r[0], r[1], r[2])")
- #print("INSERT INTO ohdm.rendering_line_mholst (multilinestring_geom, valid_since, valid_until) VALUES (" + r[0] + ", " + r[1] + ", " + r[2] +") ")
- print(r[0])
- con.commit()
- except psycopg2.DatabaseError, e:
- if con:
- con.rollback()
- print 'Error %s' % e
- sys.exit(1)
- finally:
- if con:
- con.close()
- os._exit(0)
- def parent():
- from_id = 1
- to_id = 250
- i = 0
- for i in range(0,process):
- pid = os.fork()
- if pid == 0:
- child(from_id, to_id)
- else:
- pids = (os.getpid(), pid)
- print("parent: %d, child: %d\n" % pids)
- from_id = from_id + 10
- to_id = to_id + 10
- if to_id >= amount:
- to_id = amount
- i=i+1
- print "lineImporter is starting now!"
- parent()
- print ("the procedure is finally over!")
- print datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement