小编lai*_*e9m的帖子

pika,stop_consuming不起作用

我是rabbitmq和pika的新手,并且在停止消费方面遇到了麻烦.

通道和队列设置:

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue=new_task_id, durable=True, auto_delete=True)
Run Code Online (Sandbox Code Playgroud)

基本上,消费者和生产者是这样的:

消费者:

def task(task_id):
    def callback(channel, method, properties, body):
        if body != "quit":
            print(body)
        else:
            print(body)
            channel.stop_consuming(task_id)

    channel.basic_consume(callback, queue=task_id, no_ack=True)
    channel.start_consuming()
    print("finish")
    return "finish"
Run Code Online (Sandbox Code Playgroud)

制片人:

proc = Popen(['app/sample.sh'], shell=True, stdout=PIPE)
while proc.returncode is None:  # running
    line = proc.stdout.readline()
    if line:
        channel.basic_publish(
            exchange='',
            routing_key=self.request.id,
            body=line
        )
    else:
        channel.basic_publish(
            exchange='',
            routing_key=self.request.id,
            body="quit"
        )
        break
Run Code Online (Sandbox Code Playgroud)

消费者task给了我输出:

# ... output from sample.sh, as expected

quit
?}q(UstatusqUSUCCESSqU  tracebackqNUresultqNUtask_idqU
1419350416qUchildrenq]u.
Run Code Online (Sandbox Code Playgroud)

但是,"finish" …

python rabbitmq pika

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

Angular属性修饰器在最新的VSCode中抛出"Property'x'没有初始化程序..."错误

我将在这里引用Angular指南并使用此示例代码.

自从我上次更新我的Visual Studio代码以来,我已经开始在我的Angular组件.ts文件中使用Angular装饰器(例如)装饰的属性下的红色下划线@Input.在示例代码下面我会看到一个红色下划线下@Input() hero: Hero;@Input('master') masterName: string;:

import { Component, Input } from '@angular/core';

import { Hero } from './hero';

@Component({
  selector: 'app-hero-child',
  template: `
    <h3>{{hero.name}} says:</h3>
    <p>I, {{hero.name}}, am at your service, {{masterName}}.</p>
  `
})
export class HeroChildComponent {
  @Input() hero: Hero;
  @Input('master') masterName: string;
}
Run Code Online (Sandbox Code Playgroud)

以下是红色下划线的错误消息:

[ts]属性'masterName'没有初始值设定项,并且在构造函数中没有明确赋值.

我不知道为什么这些突然出现,我希望他们离开.我会喜欢做的事就是初始化一些一次性的价值,这可能是罚款,string但对类,比如Hero我绝对不希望有这样做.

提前致谢!

typescript visual-studio-code angular

9
推荐指数
2
解决办法
4705
查看次数

如何设置Control的第一个lookAt/target

我需要设置场景的初始'lookAt'点,它将是屏幕的中心和控件的旋转.如果可能的话,我宁愿设置一个点(或一个物体的位置),而不是旋转角度.

控件是OrbitControl.如果我只是在控制初始化之前设置lookAt,则在第一次用户交互时中心将恢复为(0,0,0),这会导致"间隙"...

// camera
camera = new THREE.PerspectiveCamera( 35, window.innerWidth / window.innerHeight, 0.1, 20000);
camera.position.set(0,20,20);
camera.lookAt(new THREE.Vector3(0,10,0));

// controls
controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', render );
Run Code Online (Sandbox Code Playgroud)

如何以正确的方式设置初始点?

javascript three.js

8
推荐指数
2
解决办法
7829
查看次数

Nginx proxy_no_cache和proxy_cache_bypass

这是文档:

proxy_cache_bypass
定义不从缓存中获取响应的条件.如果字符串参数的至少一个值不为空且不等于"0",则不会从缓存中获取响应:
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
proxy_cache_bypass $http_pragma $http_authorization;
可以与proxy_no_cache指令一起使用.

proxy_no_cache
定义不将响应保存到缓存的条件.如果字符串参数的至少一个值不为空且不等于"0",则不会保存响应:
proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;
proxy_no_cache $http_pragma $http_authorization;
可以与proxy_cache_bypass指令一起使用.

这是否意味着如果我想完全排除缓存中的某些内容,我应该设置两个proxy_no_cacheproxy_cache_bypass?如果我只设置proxy_cache_bypass好吗?

caching nginx

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

是否有完整的内置函数列表,无法使用关键字参数调用?

人们在答案a1,a2中提到了这一点

由于Python C级API的开发方式,许多内置函数和方法实际上没有参数的名称.

我发现它真的很烦人因为我无法通过查看文档来了解它.例如,eval

eval(表达式,globals = None,locals = None)

然后我写了这行代码

print(eval('a+b', globals={'a':1, 'b':2}))
Run Code Online (Sandbox Code Playgroud)

并得到了TypeError: eval() takes no keyword arguments.那么有这种功能的完整列表吗?如何知道函数是否允许包含关键字参数?

python arguments python-c-api

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

语法错误:无法在模块外部使用 import 语句

当我尝试在 VSC 中运行调试器时,我不断收到此错误消息。有人可以帮忙吗?这是一个屏幕截图:

我对编程和课程还很陌生,请尽可能让解释保持非常基本的内容。

在此输入图像描述

这是 JS 文件的代码。我使用 Yo Code 和 NPM 生成了一个基本的 Visual Studio 代码扩展。

    // The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import { commands, window } from 'vscode';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {

// …
Run Code Online (Sandbox Code Playgroud)

javascript visual-studio-code vscode-debugger

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

如何在tkinter中设置小部件的大小?

简单的例子:

from tkinter import *

class GUI_CMP():
    def __init__(self):
        self.tk = Tk()
        self.text = Text(self.tk,width=60,height=40)
        self.text.pack()

        self.tk.mainloop()

if __name__ == '__main__':
    gui_cmp = GUI_CMP()
Run Code Online (Sandbox Code Playgroud)

这是它的样子:

在此输入图像描述

正如你所看到的,虽然我设置width=60,height=40了,文本小部件的宽度小于它的高度.每次我使用tkinter时这都会让我感到不安.所以我的问题是:

  1. 究竟是什么4060意味着什么呢?

  2. 文本宽度小于高度的原因是什么?

  3. 进行尺寸控制的最佳方法是什么?

python tkinter

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

从"%H:%M:%S"创建日期时间的最佳方法是什么?

说我有一些格式的字符串%H:%M:%S,例如04:35:45.我想将它们转换为datetime.datetime对象,年/月/日是一样的datetime.datetime.now().

我试过了

now = datetime.now()
datetime_obj = datetime.strptime(time_string, "%H:%M:%S")
datetime_obj.year = now.year
datetime_obj.month = now.month
datetime_obj.day = now.day
Run Code Online (Sandbox Code Playgroud)

year/month/day是不可行的,因为它是只读属性.那么什么是最好的解决方案呢?

python datetime

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

在Golang中运行后台任务和服务器监听的最佳实践是什么?

我是Go的新手.假设我有一台服务器正在侦听HTTP请求,同时我需要检查Redis通知,以便我可以更新数据.以下是一个例子:

func checkExpire() {
    for {
        switch msg := pubSubConn.Receive().(type) {
        case redis.Message:
        ...
    }
}

server.ListenAndServe()
Run Code Online (Sandbox Code Playgroud)

简单地将checkExpiregoroutine 放入一个好的解决方案吗?

go func() {
    for {
        switch msg := pubSubConn.Receive().(type) {
        case redis.Message:
        ...
    }
}()
Run Code Online (Sandbox Code Playgroud)

go goroutine

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

在函数内定义类是否可接受?

在Matplotlib的文档中有一个创建雷达图表的例子,我正在尝试理解设计.http://matplotlib.org/examples/api/radar_chart.html

"""
Example of creating a radar chart (a.k.a. a spider or star chart) [1]_.

Although this example allows a frame of either 'circle' or 'polygon', polygon
frames don't have proper gridlines (the lines are circles instead of polygons).
It's possible to get a polygon grid by setting GRIDLINE_INTERPOLATION_STEPS in
matplotlib.axis to the desired number of vertices, but the orientation of the
polygon is not aligned with the radial axes.

.. [1] http://en.wikipedia.org/wiki/Radar_chart
"""
import numpy as np

import …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

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