小编Ani*_*ilJ的帖子

使用matplotlib生成平滑的线图

以下是使用matplotlib生成绘图的python脚本.

#!/usr/bin/python

import matplotlib.pyplot as plt
import time
import numpy as np
from scipy.interpolate import spline

# Local variables
x = []
y = []

# Open the data file for reading lines
datafile = open('testdata1.txt', 'r')
sepfile = datafile.read().split('\n')
datafile.close()

# Create a canvas to place the subgraphs
canvas = plt.figure()
rect = canvas.patch
rect.set_facecolor('white')

# Iterate through the lines and parse them
for datapair in sepfile:
    if datapair:
        xypair = datapair.split(' ')
        x.append(int(xypair[1]))
        y.append(int(xypair[3]))

# Define the matrix …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

13
推荐指数
1
解决办法
5万
查看次数

GPG 错误公钥不可用:NO_PUBKEY B53DC80D13EDEF05:使用 Vagrant 创建 VM 期间

我正在尝试使用 Vagrant 和相关安装 shell 脚本(如下所列)安装 K8s 集群 VM 节点。我尝试了类似问题中的一些建议,但它们对我的情况没有帮助。我在 Windows 11 上使用 virtualbox 版本 6.1.40。

为每个虚拟机准备通用软件包安装的 common.sh 脚本会导致以下错误。

controller24: W: GPG error: https://packages.cloud.google.com/apt kubernetes-xenial InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B53DC80D13EDEF05
        controller24: E: The repository 'https://apt.kubernetes.io kubernetes-xenial InRelease' is not signed.
Run Code Online (Sandbox Code Playgroud)

common.sh 文件如下。

#!/bin/bash
#
# Common setup for all servers (Control Plane and Nodes)

set -euxo pipefail

# Variable Declaration

KUBERNETES_VERSION="1.24.10-00"

# DNS Setting
sudo mkdir /etc/systemd/resolved.conf.d/
cat <<EOF | …
Run Code Online (Sandbox Code Playgroud)

virtualbox vagrant vagrantfile vagrant-windows

12
推荐指数
2
解决办法
1万
查看次数

Wiremock 错误 - 此 WireMock 实例中没有存根映射

我已经通过示例 REST/HTTP 请求模拟实现了一个基本的 WireMock。服务器代码实现如下。

使用此代码,当我从 Postman 发出 GET 请求(即 GET http://127.0.0.1:8089/some/thing)时出现以下错误。

由于此 WireMock 实例中没有存根映射,因此无法提供响应。

我的设置/代码中缺少什么?

import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.core.WireMockConfiguration;

public class MockApp {

    private WireMockServer wireMockServer;

    public MockApp(String testSpec) {
        wireMockServer = new WireMockServer(WireMockConfiguration.options().
                port(8089).
                usingFilesUnderDirectory(testSpec).
                disableRequestJournal());
    }

    public void start() {
        wireMockServer.start();
    }

    public void stop() {
        wireMockServer.stop();
    }
}
Run Code Online (Sandbox Code Playgroud)

主要功能是:

public class MockMain {

    public static void main(String[] args) {

        String baseDir = System.getProperty("user.dir");
        String testResource = baseDir + "/resources/testconfig/";

        MockAMS mockAMS = new MockAMS(testResource);

        mockAMS.start();
    } …
Run Code Online (Sandbox Code Playgroud)

java stubbing wiremock

6
推荐指数
1
解决办法
8623
查看次数

如何模拟 Kubernetes 集群/服务器?

Kubernetes OpenAPI 规范在这里托管。

https://github.com/kubernetes/kubernetes/tree/master/api/openapi-spec
Run Code Online (Sandbox Code Playgroud)

此外,此处提供了 Kubernetes 的各种客户端 API:

https://kubernetes.io/docs/reference/using-api/client-libraries/
Run Code Online (Sandbox Code Playgroud)

使用 OpenAPI 规范,我能够生成提供 REST 服务的服务器代码。但是,使用这些 K8s 客户端 API(以 Go、Java 等任一语言编写)的应用程序不直接使用这些 REST API。

我的目标是模拟 K8s 服务器以用于测试自动化并构建一个受控环境来创建各种测试场景。

是否有任何现成的 Kubernetes 模拟可用?如果没有,我们如何将客户端 API 与上述 OpenAPI 生成的 REST 服务器接口?这样,应用程序将继续使用客户端 API,但在内部,它们将与模拟的 K8s 服务器而不是真正的服务器进行通信。

请帮助选择选项。

.

mocking kubernetes

5
推荐指数
1
解决办法
1975
查看次数

使用 Tornado Websocket 进行单元测试 - 没有属性“io_loop”错误

我已经将一个龙卷风 websocket 客户端代码拼接在一起,并在我的 python 单元测试用例中使用它。这是我第一次使用 tornado websocket,对它的单元测试 API 不是很熟悉。寻找一些帮助来理解 tornado websocket 异步单元测试代码的使用和下面的案例工作。

客户端类代码:

import logging
import logging.config
import ssl
import time
import traceback

from tornado.concurrent import Future
from tornado import gen
from tornado.httpclient import HTTPError, HTTPRequest
from tornado.log import gen_log, app_log

from tornado.web import Application, RequestHandler

class TorWebSocketClient():

    def __init__(self, ip_addr, port, cookie):
        self.ip_addr = ip_addr
        self.port = port
        self.cookie = cookie
        self.sockConnected = False
        self.logger = logging.getLogger(__name__)

    def Connect(self):

        # Creating the websocket client for each test case.
        url …
Run Code Online (Sandbox Code Playgroud)

python unit-testing tornado python-unittest

4
推荐指数
1
解决办法
1000
查看次数

C++类中的循环依赖

我是C++的新手,面临循环依赖问题.有人可以帮我解决这个问题吗?

我有两节课:

class Vertex {
    string name;
    int distance;
    //Vertex path;
    int weight;
    bool known;
    list<Edge> edgeList;
    list<Vertex> adjVertexList;

public:
    Vertex();
    Vertex(string nm);
    virtual ~Vertex();
};

class Edge {
    Vertex target;
    int weight;

public:
    Edge();
    Edge(Vertex v, int w);
    virtual ~Edge();

    Vertex getTarget();
    void setTarget(Vertex target);
    int getWeight();
    void setWeight(int weight);
};
Run Code Online (Sandbox Code Playgroud)

上面的代码给出了以下错误:

  • 'Vertex'没有命名类型
  • 'Vertex'尚未申报
  • 预期')'在'v'之前

我该如何解决这个问题?

c++

2
推荐指数
1
解决办法
3010
查看次数

错误:从'<unresolved overloaded function type>'转换为非标量类型

LSR配置类定义为:

 29 namespace ns3 {
 30 namespace lsr {
 31 
 32 #include <map>
 33 #include <vector>
 34 
 35 class LsrConfig : public Object
 36 {
 37 
 38 public:
 39 
 40   LsrConfig ();
 41   ~LsrConfig ();
 42 
208 };
209
210 }} // namespace lsr,ns3
Run Code Online (Sandbox Code Playgroud)

我正在使用上面的类的实例如下.

172   //@@Set configuration.
174   Ptr<lsr::LsrConfig> lsrConfig = CreateObject<lsr::LsrConfig()>;
175   lsrConfig->SetNetworkAttributes (network, site, routerName, logLevel);
176   lsrConfig->SetHelloProtocolAttributes (helloRetries, helloTimeout, helloInterval, adjLsaBuildInterval, firstHelloInterval);
Run Code Online (Sandbox Code Playgroud)

并获得以下编译错误.有人可以解释为什么会出现这个错误?

../src/lsr-topology-reader.cc: In member function ‘ns3::Ptr<ns3::Node> ns3::LsrTopologyReader::CreateNode(std::string, double, double, std::string, std::string, std::string, std::string, double, …
Run Code Online (Sandbox Code Playgroud)

c++ stl

2
推荐指数
1
解决办法
3097
查看次数

错误:左值作为一元'&'操作数

在我的代码中,我调用这样的函数:

Simulator::Schedule (Seconds(seconds),
                     &HelloProtocol::sendScheduledInterest(seconds), this, seconds);
Run Code Online (Sandbox Code Playgroud)

这是上述功能的签名:

  /**
   * @param time the relative expiration time of the event.
   * @param mem_ptr member method pointer to invoke
   * @param obj the object on which to invoke the member method
   * @param a1 the first argument to pass to the invoked method
   * @returns an id for the scheduled event.
   */
  template <typename MEM, typename OBJ, typename T1>
  static EventId Schedule (Time const &time, MEM mem_ptr, OBJ obj, T1 a1);
Run Code Online (Sandbox Code Playgroud)

函数sendScheduledInterest()的定义是:

void …
Run Code Online (Sandbox Code Playgroud)

c++

1
推荐指数
1
解决办法
1714
查看次数

多线程websocket客户端无法正常退出

我编写了一个多线程Web套接字客户端类,以便用户的(主)线程不会阻塞run_forever()方法调用.代码似乎工作正常,除了最后,当我停止线程时,它不会干净地关闭Web套接字,我的进程不会退出.我kill -9每次都要做一个摆脱它.我尝试调用线程的join()方法来确保主线程等待子进程完成执行,但这没有帮助.

代码如下所示.你能帮助我退出/停止线程优雅吗?

import thread
import threading
import time
import websocket

class WebSocketClient(threading.Thread):

    def __init__(self, url):
        self.url = url
        threading.Thread.__init__(self)

    def run(self):

        # Running the run_forever() in a seperate thread.
        #websocket.enableTrace(True)
        self.ws = websocket.WebSocketApp(self.url,
                                         on_message = self.on_message,
                                         on_error = self.on_error,
                                         on_close = self.on_close)
        self.ws.on_open = self.on_open
        self.ws.run_forever()

    def send(self, data):

        # Wait till websocket is connected.
        while not self.ws.sock.connected:
            time.sleep(0.25)

        print 'Sending data...', data
        self.ws.send("Hello %s" % data)

    def stop(self):
        print 'Stopping the websocket...' …
Run Code Online (Sandbox Code Playgroud)

python websocket mod-pywebsocket

1
推荐指数
1
解决办法
1781
查看次数

使用JFrame以外的组件在Java GUI中显示图像

我是Java GUI编程的新手.我正在开发一个应用程序,我需要在UI上显示图像,以及其他一些按钮/控件.我有一段使用JFrame的代码.

我的要求是我想添加一些小部件,比如按钮来启动/停止显示图像等.当我使用Jframe显示图像时,它占用了整个JFrame,我无法添加其他控件.

我正在寻找可以显示图像的东西,并将其作为组件添加到JFrame中.有人可以解释一下如何做到这一点?

java user-interface swing awt

0
推荐指数
1
解决办法
6698
查看次数

带有 getopt 的 Python 命令行 arg 不起作用

我修改了此处给出的示例代码: getopt 的示例代码

如下,但它不起作用。我不确定我错过了什么。我在现有代码中添加了“-j”选项。最终,我想添加尽可能多的命令选项以满足我的需求。

当我提供如下输入时,它不会打印任何内容。

./pyopts.py -i dfdf -j qwqwqw -o ddfdf
Input file is " 
J file is " 
Output file is " 
Run Code Online (Sandbox Code Playgroud)

你能告诉我这里有什么问题吗?

#!/usr/bin/python

import sys, getopt

def usage():
    print 'test.py -i <inputfile> -j <jfile> -o <outputfile>'

def main(argv):
   inputfile = ''
   jfile = ''
   outputfile = ''
   try:
      opts, args = getopt.getopt(argv,"hij:o:",["ifile=","jfile=","ofile="])
   except getopt.GetoptError:
      usage()
      sys.exit(2)
   for opt, arg in opts:
      if opt == '-h':
         usage()
         sys.exit()
      elif opt in ("-i", "--ifile"):
         inputfile = arg 
      elif opt …
Run Code Online (Sandbox Code Playgroud)

python getopt

-1
推荐指数
1
解决办法
1303
查看次数