分类 代码分析 下的文章

ubuntu下如何把语言环境变量改为中文

查看当前系统的语言环境

ubuntu@VM-14-193-ubuntu:~$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US:
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=
ubuntu@VM-14-193-ubuntu:~$

编辑配置文件

ubuntu@VM-14-193-ubuntu:~$ vim ~/.profile
# 添加下面内容
export LANG="zh_CN.UTF-8"
export LC_ALL="zh_CN.UTF-8"

- 阅读剩余部分 -

使用python多线程threadpool遇到"'NoneType' object has no attribute 'Empty'"的问题

代码如下:

#!/usr/bin/env python
# coding=utf8


import threadpool as tp

args = []
for i in range(1, 20):
    args.append(i)


def start(args):
    print '[+] %s' % args
    return True

pool = tp.ThreadPool(20)
reqs = tp.makeRequests(start, args)
[pool.putRequest(req) for req in reqs]
pool.wait()

执行后报错信息如下:

Exception in thread Thread-8 (most likely raised during interpreter shutdown):Exception in thread Thread-7 (most likely raised during interpreter shutdown):

省略部分信息

<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'Empty'

- 阅读剩余部分 -

可恶的BOM头!!!

原因

同事反馈一个接口返回的json数据,在python里load不出来。

Traceback (most recent call last):
  File "<pyshell#22>", line 1, in <module>
    r.json()
  File "C:\Python27\lib\site-packages\requests\models.py", line 797, in json
    return json.loads(self.text, **kwargs)
  File "C:\Python27\lib\json\__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "C:\Python27\lib\json\decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python27\lib\json\decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

查了下说是前面多了个BOM头。

- 阅读剩余部分 -

设置PHP服务器的环境变量

通过设置服务器的环境变量,来区分开发/测试/生成环境。

Apache

命令

`
SetEnv RUN_MODE development
`

Nginx

命令

`
fastcgi_param RUN_MODE development;
`

PHP获取环境变量

命令

`
$runMode = $_SERVER['RUN_MODE'];
`