s.enableStreaming(0) 试一下
我按照 https://gitee.com/dolphindb/Tutorials_CN/blob/master/OHLC.md#/dolphindb/Tutorials_CN/blob/master/data/k-line/trades.csv 教程试验
```
In [105]: import dolphindb as ddb ...: import pandas as pd ...: import numpy as np ...: csv_file = "trades.csv" ...: csv_data = pd.read_csv(csv_file, dtype={'Symbol':str} ) ...: csv_df = pd.DataFrame(csv_data) ...: s = ddb.session(); ...: s.connect("127.0.0.1",8848,"admin","123456") ...: #上传DataFrame到DolphinDB,并对Datetime字段做类型转换 ...: s.upload({"tmpData":csv_df}) ...: s.run("data = select Symbol, datetime(Datetime) as Datetime, Price, Volume from tmpData")
s.run(''' share streamTable(100:0, `Symbol`Datetime`Price`Volume,[SYMBOL,DATETIME,DOUBLE,INT]) as Trade ''')
In [110]: s.run("tableInsert(Trade,data)") Out[110]: 31196
In [117]: s.run(''' ...: share keyedStreamTable(`datetime`Symbol, 100:0, `datetime`Symbol`open`high`low`close`volume,[DATETIME,SYMBOL,DOUBLE,DOUBLE,DOUBLE,DOUBLE,LONG]) as OHLC ...: tsAggr = createTimeSeriesAggregator(name="tsAggr", windowSize=60, step=60, metrics=<[first(Price),max(Price),min(Price),last(Price),sum(volume)]>, dummyTable=Trade, outputTable ...: =OHLC, timeColumn=`Datetime, keyColumn=`Symbol, updateTime=1, useWindowStartTime=true) ...: subscribeTable(tableName="Trade", actionName="act_tsaggr", offset=0, handler=append!{tsAggr}, msgAsTable=true); ...: ...: ...: ''') Out[117]: 'localhost:8848:local8848/Trade/act_tsaggr' In [118]: try: ...: s.enableStreaming(20001) ...: except Exception as e: ...: print(s,e) ...: def handler(lst): ...: print(lst) ...: # 订阅DolphinDB(本机8848端口)上的OHLC流数据表 ...: s.subscribe("127.0.0.1", 8848, handler, "OHLC5","python_api_subscribe",0) ...: Event().wait() <dolphindb.session.session object at 0x7f1557db9130> streaming is already enabled --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-118-0b700c0dd762> in <module> 6 print(lst) 7 # 订阅DolphinDB(本机8848端口)上的OHLC流数据表 ----> 8 s.subscribe("127.0.0.1", 8848, handler, "OHLC","python_api_subscribe",0) 9 Event().wait() ~/.local/lib/python3.8/site-packages/dolphindb/session.py in subscribe(self, host, port, handler, tableName, actionName, offset, resub, filter, msgAsTable, batchSize, throttle, userName, password, streamDeserializer) 424 if msgAsTable: 425 raise ValueError("msgAsTable must be False when batchSize is 0") --> 426 self.cpp.subscribe(host, port, handler, tableName, actionName, offset, resub, filter,userName,password,sd) 427 428 ## RuntimeError: 127.0.0.1:8848 Server response: 'Failed to add publishing request to the asynchronous publisher' script: 'publishTable'
```
按照 @wfHuang2 还是出错
s.enableStreaming(0) ~/.local/lib/python3.8/site-packages/dolphindb/session.py in enableStreaming(self, port, threadCount) 387 #@endif 388 def enableStreaming(self, port, threadCount = 1): --> 389 self.cpp.enableStreaming(port,threadCount) 390 391 ## RuntimeError: streaming is already enabled