Skip to content

Commit b56d845

Browse files
committed
fix: remove dill dep && fix win signal miss
1 parent dbd430e commit b56d845

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

easyquant/main_engine.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import importlib
22
import os
33
import pathlib
4+
import signal
45
import sys
6+
import threading
57
import time
68
from collections import OrderedDict
7-
import dill
8-
import threading
99
from threading import Thread, Lock
10-
import signal
1110

1211
import easytrader
1312
from logbook import Logger, StreamHandler
@@ -43,8 +42,6 @@ def __init__(self, broker=None, need_data=None, quotation_engines=None,
4342
need_data_file = pathlib.Path(need_data)
4443
if need_data_file.exists():
4544
self.user.prepare(need_data)
46-
with open(ACCOUNT_OBJECT_FILE, 'wb') as f:
47-
dill.dump(self.user, f)
4845
else:
4946
log_handler.warn("券商账号信息文件 %s 不存在, easytrader 将不可用" % need_data)
5047
else:
@@ -91,11 +88,12 @@ def __init__(self, broker=None, need_data=None, quotation_engines=None,
9188
self.main_shutdown = [] # 引擎自身要执行的 shutdown
9289
self.after_shutdown = [] # 关闭引擎后的 shutdown
9390
self.shutdown_signals = [
94-
signal.SIGQUIT, # quit 信号
9591
signal.SIGINT, # 键盘信号
9692
signal.SIGHUP, # nohup 命令
9793
signal.SIGTERM, # kill 命令
9894
]
95+
if sys.platform != 'win32':
96+
self.shutdown_signals.append(signal.SIGQUIT)
9997

10098
for s in self.shutdown_signals:
10199
# 捕获退出信号后的要调用的,唯一的 shutdown 接口
@@ -139,7 +137,6 @@ def load(self, names, strategy_file):
139137
# 注销策略的监听
140138
old_strategy = self.get_strategy(strategy_module.Strategy.name)
141139
if old_strategy is None:
142-
print(18181818, strategy_module_name)
143140
for s in self.strategy_list:
144141
print(s.name)
145142
self.log.warn(u'卸载策略: %s' % old_strategy.name)
@@ -156,7 +153,7 @@ def load(self, names, strategy_file):
156153
if names is None or strategy_class.name in names:
157154
self.strategies[strategy_module_name] = strategy_class
158155
# 缓存加载信息
159-
new_strategy = strategy_class(log_handler=self.log, main_engine=self)
156+
new_strategy = strategy_class(user=self.user, log_handler=self.log, main_engine=self)
160157
self.strategy_list.append(new_strategy)
161158
self._cache[strategy_file] = mtime
162159
self.strategy_listen_event(new_strategy, "listen")

easyquant/push_engine/base_engine.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
# coding: utf-8
2-
import dill
2+
import time
33
from threading import Thread
44

55
import aiohttp
66

7-
import time
87
from easyquant.event_engine import Event
98

109
ACCOUNT_OBJECT_FILE = 'account.session'
@@ -16,8 +15,6 @@ class BaseEngine:
1615
PushInterval = 1
1716

1817
def __init__(self, event_engine, clock_engine):
19-
with open(ACCOUNT_OBJECT_FILE, 'rb') as f:
20-
self.user = dill.load(f)
2118
self.event_engine = event_engine
2219
self.clock_engine = clock_engine
2320
self.is_active = True
@@ -49,7 +46,7 @@ def fetch_quotation(self):
4946
def init(self):
5047
# do something init
5148
pass
52-
49+
5350
def wait(self):
5451
interval = self.PushInterval
5552
if interval < 1:

easyquant/strategy/strategyTemplate.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
# coding:utf-8
22
import sys
33
import traceback
4-
import dill
5-
6-
ACCOUNT_OBJECT_FILE = 'account.session'
74

85

96
class StrategyTemplate:
107
name = 'DefaultStrategyTemplate'
118

12-
def __init__(self, log_handler, main_engine):
13-
with open(ACCOUNT_OBJECT_FILE, 'rb') as f:
14-
self.user = dill.load(f)
9+
def __init__(self, user, log_handler, main_engine):
10+
self.user = user
1511
self.main_engine = main_engine
1612
self.clock_engine = main_engine.clock_engine
1713
# 优先使用自定义 log 句柄, 否则使用主引擎日志句柄
@@ -81,4 +77,4 @@ def shutdown(self):
8177
关闭进程前调用该函数
8278
:return:
8379
"""
84-
pass
80+
pass

0 commit comments

Comments
 (0)