我有一个环境变量,我使用profile.d设置(在Centos 6上),如下所示:
[bankap@tnt-integration-test ~]$ cat /etc/profile.d/tnt.sh
TNT_SERVER_URL=http://tnt-integration-test:8000/
Run Code Online (Sandbox Code Playgroud)
当我登录时,我看到变量:
[bankap@tnt-integration-test ~]$ echo $TNT_SERVER_URL
http://tnt-integration-test:8000/
Run Code Online (Sandbox Code Playgroud)
但是当我使用Python访问该东西时,环境变量不会显示出来!
[bankap@tnt-integration-test ~]$ python -c 'import os;os.environ.get("TNT_SERVER_URL")'
Traceback (most recent call last):
File "<string>", line 1, in <module>
NameError: name 'TNT_SERVER_URL' is not defined
Run Code Online (Sandbox Code Playgroud)
我甚至尝试使用ctypes库,结果相同:
>>> os.getenv('TNT_SERVER_URL')
>>> from ctypes import CDLL, c_char_p
>>> getenv = CDLL('libc.so.6').getenv
>>> getenv('TNT_SERVER_URL')
0
>>>
Run Code Online (Sandbox Code Playgroud)
但其他变量恰好通过......
os.environ {'SSH_ASKPASS':'/ usr/libexec/openssh/gnome-ssh-askpass','LESSOPEN':'| /usr/bin/lesspipe.sh%s','SSH_CLIENT':'139.126.176.137 56535 22','SELINUX_USE_CURRENT_RANGE':'','LOGNAME':'bankap','USER':'bankap','QTDIR':'/ usr/lib64/qt-3.3','PATH':'/ usr/lib64 /qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/bankap/bin',
有人有什么想法吗?我以前从未见过这个!
我有一个 ember 组件,它正在导入一个枚举类型,如下所示:
import { StateNames, CardSummary } from '../../types/snowcat/state-types'
Run Code Online (Sandbox Code Playgroud)
类型文件如下:
export enum CardState {
error = 'error',
new = 'new',
okay = 'okay',
warning = 'warning',
}
Run Code Online (Sandbox Code Playgroud)
然后我在组件中使用枚举如下:
@computed('cardSummary.cardState')
get type(): string {
if ([CardState.new, CardState.okay, CardState.warning].includes(this.cardSummary.cardState)) {
return 'info'
}
return 'error'
}
Run Code Online (Sandbox Code Playgroud)
代码看起来一切正常。我没有得到任何打字稿错误代码时建立的,但我我得到一个运行时错误:
loader.js:247 Uncaught Error: Could not find module `types/snowcat/state-types` imported from `snowcat/models/certificate`
at missingModule (loader.js:247)
at findModule (loader.js:258)
at Module.findDeps (loader.js:168)
at findModule (loader.js:262)
at requireModule (loader.js:24)
at r (loader.js:176)
at ember-data.js:39
at …Run Code Online (Sandbox Code Playgroud) 我有点困惑的是Python如何分配内存和垃圾收集,以及它是如何特定于平台的.例如,当我们比较以下两个代码片段时:
片段A:
>>> id('x' * 10000000) == id('x' * 10000000)
True
Run Code Online (Sandbox Code Playgroud)
代码片段B:
>>> x = "x"*10000000
>>> y = "x"*10000000
>>> id(x) == id(y)
False
Run Code Online (Sandbox Code Playgroud)
Snippet A返回true,因为当Python分配内存时,它会在第一次测试的同一位置分配它,并在第二次测试的不同位置分配,这就是它们的内存位置不同的原因.
但显然系统性能或平台会对此产生影响,因为当我尝试更大规模时:
for i in xrange(1, 1000000000):
if id('x' * i) != id('x' * i):
print i
break
Run Code Online (Sandbox Code Playgroud)
Mac上的一位朋友试过这个,直到最后.当我在一堆Linux VM上运行它时,它总会在不同的VM上返回(但在不同的时间).这是因为在Python中调度垃圾收集?是因为我的Linux虚拟机处理速度低于Mac,还是Linux Python实现垃圾收集方式不同?
我有一个相对较小的Ember/TypeScript应用程序,我已经工作了大约六个月.我曾经用如下定义计算属性:
@computed('styleNamespace', 'status')
statusClass(componentClassName: string, status: string): string {
return `${componentClassName}--${status}`
}
Run Code Online (Sandbox Code Playgroud)
但是我从来没有能够正确地通过TypeScript检查.在回顾了Chris Krycho的Emberconf培训材料后,似乎"正确"的方法如下:
@computed('styleNamespace', 'status')
get statusClass(this: CertificateCard): string {
return `${this.get('styleNamespace')}--${this.get('status')}`
}
Run Code Online (Sandbox Code Playgroud)
它是否正确?我似乎错过了什么,但因为我仍然得到这样的错误:
Error: Assertion Failed: Attempted to apply @computed to statusClass,
but it is not a native accessor function.
Try converting it to `get statusClass()`
Run Code Online (Sandbox Code Playgroud) 我开始使用pymongo(版本2.2.1)ReplicaSetConnection对象而不是pymongo.Connection对象.现在,当我从数据库执行读取时,例如:
if cur.count() == 0:
raise NoDocumentsFound(self.name, self.COLLECTION_NAME)
elif cur.count() > 1:
raise TooManyDocumentsFound(self.name, self.COLLECTION_NAME)
cur.rewind()
rec = cur[0]
Run Code Online (Sandbox Code Playgroud)
我有时会在最后一行收到" IndexError:Cursor实例没有这样的项 ".从我可以找到有关此错误的所有内容,只有当您没有任何与您的查询匹配的记录时才会发生此错误.但是,我已经清楚地检查过我的光标中有项目.ReplicaSetConnection是否存在奇怪的问题,这使得这些读取操作更加不稳定?
我有一个React组件,需要在一个setTimeout()调用中运行检查.以下是我的方法调用
componentDidUpdate: function () {
// Despite console warnings, React does *not* do this.
var boundCheck = this.checkYourself.bind(this);
if (!this.timeoutId) {
this.timeoutId = window.setTimeout(function () {
boundCheck();
}, UPDATE_CHECK_INTERVAL);
}
},
Run Code Online (Sandbox Code Playgroud)
这将在控制台上产生以下警告:
bind():您正在将组件方法绑定到组件.React会以高性能方式自动为您执行此操作,因此您可以安全地删除此调用.
但是,如果我将方法更改为以下内容:
componentDidUpdate: function () {
if (!this.timeoutId) {
this.timeoutId = window.setTimeout(function () {
this.checkYourself();
}, UPDATE_CHECK_INTERVAL);
}
},
Run Code Online (Sandbox Code Playgroud)
因为this引用,我得到一个例外window.有没有办法做到这一点,让React快乐?
ember.js ×2
linux ×2
python ×2
typescript ×2
javascript ×1
mongodb ×1
pymongo ×1
reactjs ×1
replication ×1