Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import *
- import threading
- import pandas as pd
- import json
- import time
- import datetime
- import thread
- #Global Info variable
- info = pd.DataFrame()
- def getInfo():
- global info
- while 1:
- print "Information retrieval running"
- try:
- #This will bring the required info as pandas df
- info = retriveInfoFromDB()
- except:
- pass
- time.sleep(3600)
- def runServer():
- global info
- address = ('localhost', 6005)
- server_socket = socket(AF_INET, SOCK_DGRAM)
- server_socket.bind(address)
- while(1):
- print "Listening"
- recv_data, addr = server_socket.recvfrom(2048)
- server_socket.sendto(info.to_json(path_or_buf = None, orient = 'records', date_format = 'epoch', double_precision = 10, force_ascii = True, date_unit = 'ms', default_handler = None), addr)
- th1 = threading.Thread(target=runServer)
- th2 = threading.Thread(target=getInfo)
- th1.start()
- th2.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement