我一直在使用请求/应用程序上下文一段时间没有完全理解它是如何工作的,或者为什么它的设计方式如此.当涉及请求或应用程序上下文时,"堆栈"的目的是什么?这两个独立的堆栈,还是它们都是一个堆栈的一部分?请求上下文是否被压入堆栈,还是堆栈本身?我可以在彼此之上推送/弹出多个上下文吗?如果是这样,我为什么要这样做呢?
对于所有问题感到抱歉,但在阅读请求上下文和应用程序上下文的文档后,我仍然感到困惑.
我目前正在使用tmux和xterm-256color $ TERM变量.当在tmux下的bash中时,按home/end会插入波形符(〜).在tmux之外,home/end键工作正常.
使用cat和tput,我可以看到生成序列和预期序列之间存在不匹配:
$ cat -v # pressing home, then end
^[[1~^[[4~
$ tput khome | cat -v; echo
^[OH
$ tput kend | cat -v; echo
^[OF
Run Code Online (Sandbox Code Playgroud)
为了解决这个问题,我决定将以下内容添加到我的.bashrc中:
if [[ -n "$TMUX" ]]; then
bind '"\e[1~":"\eOH"'
bind '"\e[4~":"\eOF"'
fi
Run Code Online (Sandbox Code Playgroud)
这解决了bash的问题,但是在其他readline程序中,例如在诸如ipython之类的REPL中,它仍然为home/end插入了代字号.
为什么这首先是一个问题呢?当我在tmux内部与外部时,为什么生成的序列不同?如何解决这个问题,以免在任何程序中出现问题?
我有一个返回promise的库中的函数.我需要多次运行此函数,但每次迭代必须等到上一个任务完成.
我的假设是我能做到这一点:
promiseReturner(1)
.then(promiseReturner(2)
.then(promiseReturner(3)
.then(...)
Run Code Online (Sandbox Code Playgroud)
可以使用循环简化:
var p = Promise.resolve();
for (var i=1; i<=10; i++) {
p = p.then(promiseReturner(i));
}
Run Code Online (Sandbox Code Playgroud)
但是,当我这样做时,链中的每个承诺都会同时执行,而不是一个接一个地执行,.then()似乎意味着.显然,我遗漏了一些关于承诺的基本信息 - 但在阅读了几篇教程和博客文章后,我仍然迷失了.
我找不到任何显示如何执行此操作的文档,因此我尽力弄明白(这不是常见的用例)吗?我已经设置了我的资源以使用IAM身份验证,设置CORS等.然后我部署了它,并下载了生成的SDK.
在客户端,我使用AWS.CognitoIdentityCredentials中的凭据和apigClientFactory.newClient.当我尝试发布到我的资源时,我收到403错误响应,没有正文.
响应标头包含: x-amz-ErrorType: UnrecognizedClientException
这个错误可能来自其他一些AWS服务(它们会像那样冒泡)吗?如果是这样,我怎么知道哪一个?还有什么可能导致错误?
我正在使用测试测试客户端的代码如下所示:
function onFacebookLogin(fbtoken) {
// get cognito credentials
AWS.config.credentials = new AWS.CognitoIdentityCredentials({
IdentityPoolId: 'us-east-1:abcd6789-1234-567a-b123-12ab34cd56ef',
Logins: {'graph.facebook.com': fbtoken}
});
AWS.config.credentials.get(function(err) {
if (err) {return console.error('Credentials error: ', err);}
/* I'm assuming that this is what I use for accessKey and secretKey */
var credentials = AWS.config.credentials;
apigClient = apigClientFactory.newClient({
accessKey: credentials.accessKeyId,
secretKey: credentials.secretAccessKey
});
});
}
Run Code Online (Sandbox Code Playgroud) javascript amazon-web-services amazon-cognito aws-lambda aws-api-gateway
W391 规定文件末尾应该有一个(且只有一个)空行。然而,当文件末尾至少有一个换行符时,flake8 会报告错误:
$ cat /tmp/test.py
def hello():
print('hello')
hello()
Run Code Online (Sandbox Code Playgroud)
$ hexdump -C /tmp/test.py
00000000 64 65 66 20 68 65 6c 6c 6f 28 29 3a 0a 20 20 20 |def hello():. |
00000010 20 70 72 69 6e 74 28 27 68 65 6c 6c 6f 27 29 0a | print('hello').|
00000020 0a 0a 68 65 6c 6c 6f 28 29 0a 0a |..hello()..|
0000002b
Run Code Online (Sandbox Code Playgroud)
您可以在上面看到,文件末尾实际上只有一个空行(0a is \n)。但是,当我运行 flake8 时,出现 W391 错误:
$ flake8 /tmp/test.py
/tmp/test.py:6:1: …Run Code Online (Sandbox Code Playgroud) 尝试在 ubuntu 18.04 上使用 pip 安装 uwsgi 时出现以下错误:
$ sudo pip3 install uwsgi
...
plugins/python/uwsgi_python.h:2:10: fatal error: Python.h: No such file or directory
#include <Python.h>
^~~~~~~~~~
compilation terminated.
Run Code Online (Sandbox Code Playgroud)
我已经安装了python-dev和python3-dev包。运行locate Python.h显示确实安装了:
/usr/include/python2.7/Python.h
/usr/include/python3.6m/Python.h
Run Code Online (Sandbox Code Playgroud)
我试过同时使用pipand 进行安装pip3,但出现相同的错误。每隔回答这个问题分有python-dev或python3-dev或其变型安装的,我已经尝试了所有这些。任何想法还有什么可能导致这种情况?
我有一个从空白模板开始的雪地项目。我的 index.js 文件从我正在开发的另一个模块中调用一个函数,我已经使用npm link.
当我更改另一个模块中的文件时,它不会在 snowpack 中更新。即使我重新启动开发服务器,它也不会更新。我必须用--reload清除缓存的参数重新启动snowpack 。
如何确保node_modules雪包识别对文件的更改以便重建它们?
我有以下内容ipython_config.py:
print "Test autoreload" #confirm this gets loaded
c = get_config()
c.InteractiveShellApp.extensions = ['autoreload']
c.InteractiveShellApp.exec_lines = ['%autoreload 2']
Run Code Online (Sandbox Code Playgroud)
它似乎适用于普通的 ipython 会话:
$ ipython
Test autoreload
In [1]: %autoreload 2
In [2]:
Run Code Online (Sandbox Code Playgroud)
但是,当使用使用 IPython.embed() 的嵌入式 shell 脚本时,自动重新加载魔法不再起作用。
例如,在shell.py:
from IPython import embed
embed()
Run Code Online (Sandbox Code Playgroud)
这仍然会加载我的 ipython_config.py,正如"Test autoreload"打印出来的那样,但是没有加载 autoreload 扩展(没有 %autoreload 魔法):
$ python shell.py
Test autoreload
In [1]: %autoreload 2
ERROR: Line magic function `%autoreload` not found.
Run Code Online (Sandbox Code Playgroud) 我想在使用django shell时使以下ipython命令永久生效:
%load_ext autoreload
%autoreload 2
Run Code Online (Sandbox Code Playgroud)
不幸的是,Django似乎没有使用我的全局ipython配置,因此将它们放在default_profile中似乎不起作用。在运行django shell时,有什么方法可以自动执行这些操作?
我有一个装饰器,我想用它来装饰类方法。在下面的示例中,@mydec 装饰器本身可以正常工作,但是在使用 help() 或 pydoc 时它不会保留函数签名。为了解决这个问题,我查看了使用 @decorator python-decorator 包:
import functools
import decorator
@decorator.decorator
def mydec(func):
@functools.wraps(func)
def inner(cls, *args, **kwargs):
# do some stuff
return func(cls, *args, **kwargs)
return inner
class Foo(object):
@classmethod
@mydec
def bar(cls, baz='test', qux=None):
print (baz, qux)
Foo.bar()
Run Code Online (Sandbox Code Playgroud)
不幸的是,这会导致以下异常:
Traceback (most recent call last):
File "/tmp/test.py", line 21, in <module>
Foo.bar()
File "<string>", line 2, in bar
TypeError: mydec() takes exactly 1 argument (4 given)
Run Code Online (Sandbox Code Playgroud)