VS Code 中的调试器仅工作一次(使用调试或不调试启动),之后就根本无法启动。然后我必须重新启动 VS Code,它就可以工作了。自从更新到 v1.18.1 后我才遇到这个问题。
{
"version": "0.2.0",
"configurations": [
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${file}",
"cwd": "${workspaceRoot}",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
Run Code Online (Sandbox Code Playgroud) 我有这个python代码。结果是TopTest: attr1=0, attr2=1
X 很好,但结果是SubTest: attr1=2, attr2=3
Y,我不太明白。
基本上,我有一个类属性,它是一个计数器,它在__init__ method
. 当我启动 Y 时,计数器设置为 2,然后才分配属性。我不明白为什么它从 2 开始。子类不应该复制超类并且计数器从 0 重新开始吗?
class AttrDisplay:
def gatherAttrs(self):
attrs = []
for key in sorted(self.__dict__):
attrs.append('%s=%s' % (key, getattr(self, key)))
return ', '.join(attrs)
def __repr__(self):
return '[%s: %s]' % (self.__class__.__name__, self.gatherAttrs())
class TopTest(AttrDisplay):
count = 0
def __init__(self):
self.attr1 = TopTest.count
self.attr2 = TopTest.count+1
TopTest.count += 2
class SubTest(TopTest):
pass
X, Y = TopTest(), SubTest()
print(X)
print(Y)
Run Code Online (Sandbox Code Playgroud) 我有下面的循环,但无法使用assign
或矢量化它,因为我正在进一步修改多个对象和函数。然而,pandas 选择占用了大部分执行时间。有办法绕过这个吗?
if date in data[instrument].index:
row = data[instrument].ix[date]
Run Code Online (Sandbox Code Playgroud)
34124 0.04444 1.302e-06 7.085 0.0002076 索引.py:108(_getitem)
34124 0.08395 2.46e-06 7.029 0.000206 索引.py:1044(_getitem_axis)
编辑:事实证明,这dict.__getitem__
比上述使用 pandas 的方法要快得多。因此,我可以用这样的方法来转换所有内容:
dict[(date, instrument)] = pd.Series.to_dict(data[instrument].ix[date]).
Run Code Online (Sandbox Code Playgroud)
我只需要设置一次,我将多次重复使用的其余代码现在速度提高了大约 54 倍。
我正在寻求实现一个 Web 服务器,它将接收所有美国股票(大约 10,000 个)的流数据。我想知道是否有最适合此目的的特定基础设施。我计划将 Gunicorn 服务器与 Gevent 一起使用。
一个瓶颈是将这些数据保存到数据库中。是否可以先将数据保存到 Redis 流中,然后批量发送到数据库以避免 CPU 过载?直接保存每只股票的每条 WebSocket 消息将需要太多资源。
我有一个悬停时展开和缩回的菜单。问题是菜单有很多元素,要触发我的扩展功能,我需要编写如下内容。我的实际代码包含更多代码,我想知道是否有更好的方法来做到这一点。
var e = event.target
if(
e.parentNode.className.split(" ")[0] === "main-section" ||
e.parentNode.parentNode.className.split(" ")[0] === "main-section" ||
e.parentNode.parentNode.parentNode.className.split(" ")[0] === "main-section"){
//do somehtings}
Run Code Online (Sandbox Code Playgroud) python ×4
counter ×1
html ×1
init ×1
javascript ×1
loops ×1
pandas ×1
redis ×1
subclass ×1
timescaledb ×1