我看到与特定编程语言相关的现有问题.特定语言存在实施差异,但是存在理论上的概念差异吗?
Mutable vs immutable:在Python中,列表是完全可变的,而元组是不可变的或持久不可变的,因此修改创建新的元组并且不进行就地修改.但这纯粹是一个实现细节.在其他语言中,元组是可变的,列表是不可变的.
异构与同构:从语义上讲,元组通常是异构的,而列表通常是同构的,但这更像是一种约定,并且有很多例外.像Python这样的动态类型语言具有异构列表.例如,Haskell支持称为HList的完全静态类型的异构列表.
有限与无限:从理论上讲,列表可以是无限的,一些编程语言(Haskell)支持无限列表.元组不可能是无限的.
更新:唯一的理论差异是元组必须是有限的,而列表理论上可以是无限的.其余的差异是纯粹的实现差异.
维基百科说"元组是一个有限的有序元素列表."
这清楚地表明元组是一个列表,而是一个有限列表.
我创建了一个带有路线的蓝图,并使用我的 Flask 应用程序注册了该蓝图。但是,我在请求路线时收到 404。我的代码有什么问题吗?
from flask import Flask, Blueprint
bp = Blueprint('test', __name__)
app = Flask(__name__)
app.register_blueprint(test_blueprint, url_prefix='/test')
@bp.route('/')
def home_route():
return "This is the home route."
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud)
from flask import Flask, Blueprint
bp = Blueprint('test', __name__)
app = Flask(__name__)
app.register_blueprint(test_blueprint, url_prefix='/test')
@bp.route('/')
def home_route():
return "This is the home route."
if __name__ == '__main__':
app.run()
Run Code Online (Sandbox Code Playgroud) 这应该是一个非常简单的问题,但在谷歌搜索,阅读文档和其他几个SO线程后,我没有看到答案:如何使用Python标准日志记录异常?一个小皱纹是我从未来获得例外.我except自己不是在编写异常处理程序.理想情况下,我会得到异常消息,堆栈跟踪,发送的额外消息,以及可能的异常类型.这是一个显示我的问题的简单程序:
import logging
from concurrent.futures import ThreadPoolExecutor
logger = logging.getLogger(__name__)
def test_f(a, b=-99, c=50):
logger.info("test_f a={} b={} c={}".format(a, b, c))
def future_callback_error_logger(future):
e = future.exception()
if e is not None:
# This log statement does not seem to do what I want.
# It logs "Executor Exception" with no information about the exception.
# I would like to see the exception type, message, and stack trace.
logger.error("Executor Exception", exc_info=e)
def submit_with_log_on_error(executor, func, *args, **kwargs):
future = executor.submit(func, *args, …Run Code Online (Sandbox Code Playgroud) 以下statement_timeout选项可在某些Postgresql数据库上使用,而在其他数据库上则可使用Unsupported startup parameter: options。为什么?
这可能是Postgres 9.4和9.6之间的区别吗?这适用于前者的服务器,而不适用于后者。
from sqlalchemy import create_engine
# As is: Unsupported startup parameter: options
db_engine = create_engine("postgresql://user:pw@host/database",
connect_args={"options": "-c statement_timeout=1000"})
with db_engine.connect() as db_connection:
print("got it")
Run Code Online (Sandbox Code Playgroud)
具体来说,我得到:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) ERROR: Unsupported startup parameter: options
Run Code Online (Sandbox Code Playgroud) 对于 Kafka Connect 连接器或连接器任务失败或遇到错误的场景,是否有任何警报选项?
我们运行了 Kafka Connect,它运行良好,但我们遇到了需要手动跟踪和发现的错误。通常,在人类注意到问题之前,它已经处于错误状态一个星期。
Julia 有一个内置函数可以四舍五入到n有效数字。signif(0.0229, 2)将四舍五入到两位有效数字并给出0.023.
我怎样才能截断或截断到n有效数字,以便我能得到0.022呢?
运行Web应用程序背后HAProxy的1.6.3-1ubuntu0.1,我越来越HAProxy的统计qtime,ctime,rtime,ttime值0,0,0,2704。
从文档(https://www.haproxy.org/download/1.6/doc/management.txt):
58. qtime [..BS]: the average queue time in ms over the 1024 last requests
59. ctime [..BS]: the average connect time in ms over the 1024 last requests
60. rtime [..BS]: the average response time in ms over the 1024 last requests
(0 for TCP)
61. ttime [..BS]: the average total session time in ms over the 1024 last requests
Run Code Online (Sandbox Code Playgroud)
我期望响应时间在 0-10 毫秒范围内。ttime2704 毫秒似乎高得不切实际。是否有可能单位关闭,这是 2704 微秒而不是 2704 毫秒?
其次,它ttime …
我想使用名为 warp 的第三方库编译一个简单的 Rust 程序:
[package]
name = "hello-world-warp"
version = "0.1.0"
[dependencies]
warp = "0.1.18"
Run Code Online (Sandbox Code Playgroud)
在src/main.rs:
[package]
name = "hello-world-warp"
version = "0.1.0"
[dependencies]
warp = "0.1.18"
Run Code Online (Sandbox Code Playgroud)
当我运行时,cargo build我看到它下载了 warp 和大量传递依赖项,然后出现错误:
use warp::{self, path, Filter};
fn main() {
// GET /hello/warp => 200 OK with body "Hello, warp!"
let hello = warp::path!("hello" / String)
.map(|name| format!("Hello, {}!", name));
warp::serve(hello)
.run(([127, 0, 0, 1], 3030));
}
Run Code Online (Sandbox Code Playgroud)
我已经阅读了有关模块和板条箱的各种文档。在这个简单的场景中我做错了什么?
我想在我的 AWS ECS/Fargate 集群上的公共 Docker 映像中启动交互式 shell,以从集群内部运行网络/连接测试。
似乎执行此操作的官方方法是后跟aws ecs run-task[ aws ecs execute-command1][2]
如果可能的话,我想使用现有的公共 Docker Hub 映像,而不是构建自定义映像。
如果我run-task不使用任何命令或使用默认命令运行 do,则任务将退出并且execute-command无法处理已退出的任务。
"Essential container in task exited"
Run Code Online (Sandbox Code Playgroud)
如果我设置 Docker 命令sleep 10000,我会得到:
"CannotStartContainerError: ResourceInitializationError: failed to create new container runtime task: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: \"sleep 10000\": executable file not found in $PATH: unknown",
Run Code Online (Sandbox Code Playgroud)
理想情况下,运行任务和执行命令将合并在一个步骤中。我不希望后台任务无限期地运行,我想要一个 shell 交互式地运行一些命令,当我完成时会被清理。我将如何实现这一目标?
[2] https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html
这是一个简单、普通的 Kafka Streams 应用程序,使用EXACTLY_ONCE_V2.
configurationParameters.put(StreamsConfig.PROCESSING_GUARANTEE_CONFIG, StreamsConfig.EXACTLY_ONCE_V2);
Run Code Online (Sandbox Code Playgroud)
我看到的错误如下。如果我删除上面提到的 EXACTLY_ONCE_V2 设置,此错误就会消失,并且流应用程序运行数天不会出现错误。错误日志是:
[错误] 2021-11-27 18:10:23.141 [kafka-生产者-网络线程 | id-mapping-app-1eede139-ace6-4aff-9e94-ca508cb9c98d-StreamThread-1-生产者] RecordCollectorImpl - 流线程 [id-mapping-app-1eede139-ace6-4aff-9e94-ca508cb9c98d-StreamThread-1] 任务 [ 0_11] 将记录发送到任务 0_11 的主题数据记录输出时遇到错误,原因是:org.apache.kafka.common.errors.InvalidProducerEpochException:生产者尝试使用旧纪元进行生产。由于生产者被隔离,因此不会记录写入的偏移量,也不会发送更多记录,表明任务可能会被迁移出去
该应用程序使用 Kafka Streams 3.0.0,这是撰写本文时的最新版本。Gradle 风格的 Maven 坐标是:org.apache.kafka:kafka-streams:3.0.0
Kafka 代理在 Kubernetes 上的 Strimzi 0.23.0 下运行 Kafka 2.8.0。
我在使用 Flink 框架而不是 Kafka Streams 的类似应用程序中也遇到了完全相同的错误消息:
Flink 1.13.2:“ProducerFencedException:生产者尝试使用旧纪元进行操作”
在 Flink 和 Kafka Streams 中,仅禁用一次即可使错误消失。如果我在处理后恰好打开一次,就会发生错误。
apache-kafka ×2
python ×2
amazon-ecs ×1
aws-fargate ×1
docker ×1
exception ×1
flask ×1
haproxy ×1
import ×1
julia ×1
latency ×1
list ×1
logging ×1
metrics ×1
module ×1
postgresql ×1
rust ×1
rust-cargo ×1
rust-crates ×1
sqlalchemy ×1
theory ×1
tuples ×1