我有一个用python2.7编写的脚本,为了调试目的,我使用一个catch-all语句来捕获和打印所有异常.出于某种原因,有时会发现异常None.什么可能导致这种情况发生?
代码是这样的:
from __future__ import print_function
try:
run_arbitrary_code()
except Exception as e:
print(e)
Run Code Online (Sandbox Code Playgroud)
输出是:
None
None
None
None
Run Code Online (Sandbox Code Playgroud)
我从来没有经历过异常None,并想知道是什么导致这种情况.
为了回答一些评论,该功能做了很多.它包括图形搜索以及通过套接字发送和接收JSON数据等内容,因此有很多事情可能出错.但是这里的问题是引发异常None,这对我的调试根本没有帮助.
我试图通过Gatling进行简单的性能测试.我用maven来运行这个过程.为了在代码中的更改破坏我的gatling-tests时轻松获取,我希望maven-build失败.我已确保添加<failOnError>true</failOnError>我的pom.xml文件.
我目前的脚本是这样的:
class MySim extends Simulation {
val httpProtocol = http.baseURL("http://localhost:8080")
val scn = scenario("Test")
.exec(http("request_1")
.get("""/helloworld""")
.check(status.is(200))
)
setUp(scn.inject(ramp(1 users) over (1 seconds))).protocols(httpProtocol)
}
Run Code Online (Sandbox Code Playgroud)
我使用maven(使用gatling-maven-plugin)运行构建,使用mvn clean gatling:execute它将永远成功.(即使服务器没有运行).我正在寻找一种方法来确保当gatling-test失败(或者失败百分比过高)时maven构建失败.
我正在尝试创建一个服务,返回我的组件可以订阅的Observable.但是我收到以下错误:
Property 'subscribe' does not exist on type 'Observable'.
Run Code Online (Sandbox Code Playgroud)
我目前正在运行build alpha.44,下面你会发现一些代码可以重现问题.
import {Http} from 'angular2/http';
import {Observable} from 'angular2/core';
export class Backend {
http: Http;
constructor(http: Http) {
this.http = http;
this.getTeams().subscribe();
}
public getTeams(): Observable {
return this.http.get('/api/teams')
.map(JSON.parse);
}
}
Run Code Online (Sandbox Code Playgroud)
更改代码以返回"任何"类型似乎可行,但这消除了使用TypeScript的一些优点.有没有什么好方法可以在Angular2的当前版本中使用Observables的严格类型?
通过在响应中引入无状态功能组件,我们可以通过多种方式向组件添加辅助方法。关于助手功能,已定义的标准做法是什么?
辅助功能并非旨在用作通用工具功能。(这意味着它仅用于此特定组件)
将它们放在组件功能中吗?
export const myComponent = (props) => {
const myHelper = (value) => {
// Insert logic
};
return <div>{myHelper(props.mystate.value)}</div>;
};
Run Code Online (Sandbox Code Playgroud)
将它们放在函数之外,但在同一文件中?
const myHelper = (value) => {
// Insert logic
};
export const myComponent = (props) => {
return <div>{myHelper(props.mystate.value)}</div>;
};
Run Code Online (Sandbox Code Playgroud)
还是有一种常用的替代方法?
我正在尝试在Angular2中创建一个具有"重复密码"功能的注册表单.我希望这可以使用自定义验证器作为表单控件.
我遇到的问题是,当验证器运行时,"this-context"似乎被设置为验证器,因此我无法访问RegistrationForm类上的任何本地方法.我似乎无法找到从验证器访问ControlGroup的任何好方法.
任何人都知道在自定义验证器中访问同一控件组中的其他控件的好方法吗?
这是组件的简短示例:
import { Component, View } from 'angular2/angular2';
import { Validators, ControlGroup, Control, FORM_DIRECTIVES, FORM_BINDINGS } from 'angular2/angular2';
@Component({
selector: 'form-registration'
})
@View({
directives: [FORM_DIRECTIVES, ROUTER_DIRECTIVES],
template: `
<form (submit)="register($event)" [ng-form-model]="registerForm">
<label for="password1">Password:</label>
<input id="password1" ng-control="password1" type="password" placeholder="Passord" />
<label for="password2">Repeat password:</label>
<input id="password2" ng-control="password2" type="password" placeholder="Gjenta passord" />
<button class="knapp-submit" type="submit" [disabled]="!registerForm.valid">Registrer deg</button>
</form>
`
})
export class RegistrationForm {
registerForm: ControlGroup;
constructor() {
this.registerForm = new ControlGroup({
password1: new Control('', Validators.required),
password2: new Control('', this.customValidator) …Run Code Online (Sandbox Code Playgroud) angular ×2
gatling ×1
maven ×1
maven-plugin ×1
python ×1
python-2.7 ×1
reactjs ×1
scala ×1
typescript ×1