我试图运行一个带有while循环的ZeroMQ订阅,并运行一个PyQt5 Tableview,该视图仅在简单的GUI中显示您提供给它的模型中的数据。如果算上Im,还不确定如何从while循环继续运行,同时保持其运行状态,这可能就是失败的原因。我需要在创建视图运行时运行while循环
我正在尝试使用线程来运行它们,并且尝试了多处理,但是似乎两者都做不到。我是新手。
def main():
context = zmq.Context()
socket = context.socket(zmq.SUB)
print('Opening Socket...')
# We can connect to several endpoints if we desire, and receive from all.
print('Connecting to Nicks BroadCast...')
socket.connect("Server:port")
print('Connected To ____ BroadCast')
socket.setsockopt_string(zmq.SUBSCRIBE, 'H')
#string contents will always be heartbeat. Second String contents will always be fills.
while (running):
#Recieve infomration from ____ Subscription
heartbeat = socket.recv_string() # receive twice, First subject and second
route_info = socket.recv_string()
#split strings and append to lists
list_heartbeat.append(heartbeat.split())
list_fills.append(route_info.split())
#create Dataframes and format
df_heartbeat = pd.DataFrame(list_heartbeat, columns= ['H', 'Date/TimeStamp' 'OK'])
df_fills = pd.DataFrame(list_fills, columns = ['R', 'Date/Time','Qty' 'Ticker', 'Price','Fill_ID', 'Sequence','Order_Ref_ID', 'Currency Pair'])
#names = ['Date/Time', 'Side', 'Qty','Ticker','Price', 'orderid','sequence', 'tranche'])
df_fills['Price'].astype(float)
df_fills['Fill_ID'].astype(int)
df_fills['Sequence'].astype(int)
df_heartbeat['Date/Time'] = pd.to_datetime(df_heartbeat['Date/Time'])
df_fills['Date/Time'] = pd.to_datetime(df_fills['Date/Time'])
#set index of Dfs to Date and Time.
df_heartbeat.set_index('Date/Time')
df_fills.set_index('Date/Time')
print(df_heartbeat)
def createview(title, model):
import sys
app = QtWidgets.QApplication(sys.argv)
view = QtWidgets.QTableView()
view.setWindowTitle(title)
view.setModel(model)
view.resizeColumnToContents(0)
view.resizeColumnToContents(1)
view.resizeColumnToContents(2)
view.resizeColumnToContents(3)
view.resizeColumnToContents(4)
view.resizeColumnToContents(5)
view.resizeColumnToContents(6)
view.resizeColumnToContents(7)
view.resizeColumnToContents(8)
view.show()
sys.exit(app.exec_())
if __name__=="__main__":
#instead of the Read_ csv there should be dataframe from above fed into the GUI
df=pd.read_csv("C:\Excel Sheets\Fill_Test_CSV_6-18-18.csv", names = ['Date/Time', 'Side', 'Qty','Ticker','Price', 'orderid','sequence', 'tranche'])
df['Date/Time'] = pd.to_datetime(df['Date/Time'])
df['Side'] = df['Side'].astype('str')
df['Ticker'] = df['Ticker'].astype('str')
df.set_index('Date/Time', inplace=True)
df.sort_index(axis=0, ascending = False,inplace=True)
model = PandasModel(df)
thread1 = Thread(target=main())
thread2 = Thread(target=createview("Model",model))
thread1.start()
thread2.start()
这仅运行ZeroMQ订阅,而不运行我需要它运行的tableview。