Skip to content

Commit

Permalink
python startup
Browse files Browse the repository at this point in the history
  • Loading branch information
huataihuang committed Nov 26, 2023
1 parent 49c99f1 commit 1fe4c47
Show file tree
Hide file tree
Showing 17 changed files with 218 additions and 7 deletions.
16 changes: 13 additions & 3 deletions source/android/device/sony_wf-1000xm3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ SONY的蓝牙降噪耳机的控制微调功能都是在手机端应用 ``Headpho

我最初没有意识到这种自动切换的优势,但是在地铁里走动和坐下来时,就感觉这种自动模式确实非常实用。相比较Apple AirPod Pro完全由手柄控制降噪,往往会在路上忘记关闭降噪,多少有些安全隐患。

降噪的效果没有我想象的那么厉害,在地铁中依然能够听到广播报站,周围某些人说话的声音频率似乎比较容易进入(虽然也听不清)。

.. note::

对比 :ref:`airpods` 我感觉 SONY WF-1000MX3 降噪效果相对弱不少,对于外部人声隔离不足。不过,低频和高频过滤还行,所以在地铁中开启降噪还是有一定效果的。

音质应该算不错吧,至少我听人声歌曲没有什么明显失真(对比我的索尼7506 `索尼 7506 耳机真的那么棒吗? <https://www.zhihu.com/question/324908475>`_ )。不过,我拿到的二手WF-1000MX3左耳有一点点底噪,在安静的晚上能够感觉到,右耳则非常安静。当然在路途中是无法区别的...
音质应该算不错吧,至少我听人声歌曲没有什么明显失真(对比我的索尼7506) ( `索尼 7506 耳机真的那么棒吗? <https://www.zhihu.com/question/324908475>`_ )。:strike:`不过,我拿到的二手WF-1000MX3左耳有一点点底噪,在安静的晚上能够感觉到,右耳则非常安静。` (可能最近太疲劳,我发现左耳有一点点耳鸣) 当然在路途中是无法区别的...

我之所以购买真无线蓝牙降噪耳机,是希望能够配合 :ref:`samsung_galaxy_watch_4_classic_lte` 实现完全摆脱手机的自由活动:

Expand All @@ -119,6 +117,18 @@ SONY的蓝牙降噪耳机的控制微调功能都是在手机端应用 ``Headpho
- 购物(只有支付宝离线刷码)
- 公交( :ref:`samsung_pay_card` )

我感觉的遗憾
--------------

- 降噪的效果没有我想象的那么厉害,在地铁中依然能够听到广播报站,周围某些人说话的声音频率似乎比较容易进入(虽然也听不清)。也就是说 索尼WF-1000XM3 降噪能力中等(不如我使用过的 :ref:`airpods` pro 2)
- 风噪非常严重: 我在 :strike:`中等强度` 风中走过街头,满耳都是风噪,几乎无法收听音乐。这点比较失望
- 外形确实有点庞大了,不论耳机还是充电盒都比 :ref:`airpods` pro 2 大不少,外壳尤甚,塞在裤兜里稍有膈应。 ( `全网首拆:SONY索尼WF-1000XM3真无线降噪耳机 <https://www.52audio.com/archives/24818.html>`_ 可以看到充电盒使用了标准柱状电池,感觉索家对外观设计还是不如果家那么极致)

我的感受:

- 二手(300元)值得入手
- 如果全新原价不如购买 :ref:`airpods` pro 2(索尼品牌的溢价太高了)

参考
======

Expand Down
20 changes: 20 additions & 0 deletions source/big_data/maxcompute/pyodps/pyodps_startup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,27 @@ PyODPS支持在本地环境、DataWorks、PAI Notebooks中使用
.. literalinclude:: pyodps_startup/check_pyodps_install
:caption: 验证 ``PyODPS`` 安装

简单查询
=========

官方文档提供了一个简单的查询案例,我简单复述如下:

.. literalinclude:: pyodps_startup/odps_select.py
:language: python
:caption: 验证odps查询的python案例

这里我运行案例遇到一个报错:

.. literalinclude:: pyodps_startup/odps_select.py_output
:caption: 验证odps查询的python案例报错

这个报错有点迷惑,但是实际上通过一条条命令排查,会发现实际上 :ref:`python_os.environ_os.getenv` 返回的指定环境变量 ``ALIBABA_CLOUD_ACCESS_KEY_ID`` 和 ``ALIBABA_CLOUD_ACCESS_KEY_SECRET`` 是空的( ``Non`` )

原因说来很简单,原来在 ``bash`` 的 ``~/.bash_profile`` 中缺少 ``export`` 命令来明确输出环境变量就会导致 Python 的 :ref:`python_os.environ_os.getenv` 无法获得该环境变量,所以一定要规范配置环境变量:

.. literalinclude:: pyodps_startup/odps_env
:caption: ODPS相关环境变量设置
:emphasize-lines: 4


参考
Expand Down
4 changes: 4 additions & 0 deletions source/big_data/maxcompute/pyodps/pyodps_startup/odps_env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALIBABA_CLOUD_ACCESS_KEY_ID="my_id"
ALIBABA_CLOUD_ACCESS_KEY_SECRET="my_secret"

export ALIBABA_CLOUD_ACCESS_KEY_ID ALIBABA_CLOUD_ACCESS_KEY_SECRET
22 changes: 22 additions & 0 deletions source/big_data/maxcompute/pyodps/pyodps_startup/odps_select.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from odps import ODPS

def main():
# 确保 ALIBABA_CLOUD_ACCESS_KEY_ID 环境变量设置为用户 Access Key ID,
# ALIBABA_CLOUD_ACCESS_KEY_SECRET 环境变量设置为用户 Access Key Secret,
o = ODPS(
os.getenv('ALIBABA_CLOUD_ACCESS_KEY_ID'),
os.getenv('ALIBABA_CLOUD_ACCESS_KEY_SECRET'),
#os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'],
#os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'],
project='project', # 项目名
endpoint='http://service.cn-hangzhou-xxx:80/api' # 官方接口
)

result = o.execute_sql('SELECT * FROM my_table LIMIT 3')
with result.open_reader() as reader:
for record in reader:
print(record)

if __name__ == "__main__":
main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
...
TypeError: `access_id` and `secret_access_key` should be provided.
4 changes: 2 additions & 2 deletions source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
author = 'Huatai Huang'

# The short X.Y version
version = ''
version = '0.7'
# The full version, including alpha/beta/rc tags
release = '0.7'
release = 'beta'


# -- General configuration ---------------------------------------------------
Expand Down
29 changes: 28 additions & 1 deletion source/devops/docs/sphinx_doc/readthedocs_slow_builds.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Read the Docs编译缓慢的解决建议
:caption: Read the Docs 上build failed,Error是超时
:emphasize-lines: 17,18

可以看到失败退出的错误返回码 ``137`` ,也就是类似 :ref:`k8s_exit_code_137` ,表明运行程序 ``OOM`` 了
可以看到失败退出的错误返回码 ``137`` ,也就是类似 :ref:`k8s_exit_code_137` ,表明运行程序被强制杀死了...

解决建议
===========
Expand All @@ -29,6 +29,33 @@ Read the Docs编译缓慢的解决建议

- 请求更多资源: 如果还是遇到问题,则发送电子邮件给 ``support@readthedocs.org`` ,提供构建文档所需更多资源的充分理由 (类似 `Command killed due to excessive memory consumption #6627 <https://github.com/readthedocs/readthedocs.org/issues/6627>`_ 在 `GitHub: readthedocs / readthedocs.org <https://github.com/readthedocs/readthedocs.org>`_ 提交issue也能获得管理员帮助提高一定的资源限制)

最终解决
===========

我给 ``support@readthedocs.org`` 发了一封电子邮件请求更多资源,两天以后收到答复,说根据日志没有发现资源不足情况,但是把我的 ``cloud-atlas`` 项目编译时间限制放宽到1小时。我再次做了编译尝试,结果还是失败。

很郁闷...

但是我在回家路上思考这个问题的时候,想到这个编译过程确实在我的服务器上也非常长(如果 :ref:`cpu_frequency_governor` 设置为 ``powersave`` 则长达数小时)。这是非常诡异的事情,因为我记得很久以前,我曾经夸赞过 Sphinx Doc 的编译速度,当时可以在分钟级就完成完整编译。我的印象中是某个时间点开始,突然间编译速度就慢到难以忍受。只不过当时因为自己服务器没有编译限制,所以最终编译完成也就没有深究。

现在这个问题再次摆在面前,而且不得不解决...

既然是某个时间点突然变慢,那么说明很可能是某个模块升级或者配置修改导致的...我仔细回想了一下,突然想到 :ref:`sphinx_chinese_search` 失效很久了。记得刚开始配置 ``jieba`` ,我还欣喜地发现它能够神奇地切分中文,能够完成中文词汇搜索。然而,不知道何时,这个搜索功能就再也不工作了,似乎是什么模块升级导致的。

既然这个中文搜索功能失效很久了,既然编译缓慢也出现很久了,那么这两者会不会有什么关联呢?

果然,我将 :ref:`cpu_frequency_governor` 的以下 ``conf.py`` 配置取消:

.. literalinclude:: sphinx_chinese_search/conf.py
:language: python
:caption: 配置Sphinx ``conf.py`` 设置项目为中文

果然,编译速度惊人地快,仅仅三分半钟就完成了编译。再次同步到ReadTheDocs网站,也就能完成编译了。

.. note::

:ref:`sphinx_chinese_search` 问题待我有空时候再彻底解决一下

参考
=====

Expand Down
6 changes: 6 additions & 0 deletions source/devops/docs/sphinx_doc/sphinx_chinese_search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ Sphinx中文搜索
:language: python
:caption: 可选配置 ``jieba`` 词典路径

.. warning::

目前不知道什么变化导致 :ref:`readthedocs_slow_builds` ,我通过关闭中文language来恢复快速编译。不影响阅读,但是搜索功能已经很久不工作了,待有空再解决

.. note::

`readthedocs-demo-zh <https://readthedocs-demo-zh.readthedocs.io/zh-cn/latest/%E6%96%87%E4%BB%B6%E6%89%98%E7%AE%A1%E7%B3%BB%E7%BB%9F-ReadtheDocs.html>`_ 给出了一个完整构建中英文双语文档的方法,或许今后可以参考

参考
=====
Expand Down
12 changes: 11 additions & 1 deletion source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ I have a dream!

.. figure:: _static/cloud_atlas.jpg

Discovery曾经拍摄过系列纪录片 「 `Atlas <https://movie.douban.com/subject/2070580/>`_ 」,译名为「列国图志」,我希望我的 Cloud Atlas 也能够简洁生动,为大家带来如同「图志」一般的展现云计算开源技术。
目标
=======

Discovery曾经拍摄过系列纪录片 「 `Atlas <https://movie.douban.com/subject/2070580/>`_ 」,译名为「列国图志」,我希望我的 Cloud Atlas 也能够简洁生动,为大家带来如同「图志」一般的展现云计算开源技术:

- 分享是真实可复现的操作实践,没有隐瞒和遗漏(不是空洞的PPT分享)
- 真实的实践经验,无论是自己的错误(踩过的坑)还是无数次尝试找到正确的方法,都以可操作、可复现的具体步骤分享

.. note::

如果你按照我的文档无法完成,请在文章下的评论系统留言,我们一起讨论并完善指南

阅读
=========
Expand Down
17 changes: 17 additions & 0 deletions source/python/dictionary/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _python_dictionary:

=================================
Python 字典(dictionary)
=================================

.. toctree::
:maxdepth: 1

python_dictionary_startup.rst

.. only:: subproject and html

Indices
=======

* :ref:`genindex`
5 changes: 5 additions & 0 deletions source/python/dictionary/python_dictionary_startup.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.. _python_dictionary_startup:

================================
Python字典(dictionary)快速起步
================================
2 changes: 2 additions & 0 deletions source/python/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Python Atlas

intro_python.rst
startup/index
os/index
dictionary/index
network/index
database/index
gui/index
Expand Down
18 changes: 18 additions & 0 deletions source/python/os/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.. _python_os:

=================================
Python os 模块
=================================

.. toctree::
:maxdepth: 1

intro_python_os.rst
python_os.environ_os.getenv.rst

.. only:: subproject and html

Indices
=======

* :ref:`genindex`
17 changes: 17 additions & 0 deletions source/python/os/intro_python_os.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.. _intro_python_os:

===================
Python os 模块
===================

Python os 模块提供了简便的和操作系统交互的能力,以及控制系统进程。这个os模块提供了跨操作系统的能力,可以工作在 :ref:`windows` , :ref:`macos` 和 :ref:`linux` 。后续我会在实践中逐步补全本文(索引)

环境变量
==========

:ref:`python_os.environ_os.getenv` 可以获取操作系统环境变量,这在很多程序运行时需要判断环境以及获取特定的变量(例如账号密码)非常有用

参考
======

- `DigitalOcean Tutorial: Python os module <https://www.digitalocean.com/community/tutorials/python-os-module>`_
33 changes: 33 additions & 0 deletions source/python/os/python_os.environ_os.getenv.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.. _python_os.environ_os.getenv:

===================================================
Python ``os.environ`` 对象 和 ``os.getenv()`` 方法
===================================================

``os.environ``
=================

在 Python 中 ``os.environ`` 是一个用户环境变量的映射对象(mapping object)。它返回的是一个 :ref:`python_dictionary` ,其中用户的环境变量作为键(key),其值作为值(value)。由于 ``os.environ`` 是一个Python字典,所以可以执行字典的 ``get`` 和 ``set``

注意,虽然可以修改 ``os.environ`` ,但是 **任何 os.environ 修改只在当前进程有效,而不会持久化生效**

- 获取环境变量的代码片段案例:

.. literalinclude:: python_os.environ_os.getenv/environ_home.py
:language: python
:caption: 打印输出操作系统 **所有** 环境变量

环境变量获取空 ``null`` 问题
===============================

我在实践 :ref:`pyodps_startup` 遇到一个小白问题,运行 ``odps`` 测试程序报,调试发现并没有获得指定环境变量,原因就是在使用 ``os.environ`` 或者 ``os.getenv()`` ,一定要明确配置 ``export`` 指定环境变量,否则即使登陆 :ref:`bash` 看上去环境变量生效,实际 Python程序运行还是拿不到环境变量:

.. literalinclude:: ../../big_data/maxcompute/pyodps/pyodps_startup/odps_env
:caption: ODPS相关环境变量设置
:emphasize-lines: 4

参考
=====

- `Python | os.environ object <https://www.geeksforgeeks.org/python-os-environ-object/>`_
- `Python | os.getenv() method <https://www.geeksforgeeks.org/python-os-getenv-method/>`_
14 changes: 14 additions & 0 deletions source/python/os/python_os.environ_os.getenv/environ_home.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Python program to explain os.environ object

# importing os module
import os
import pprint

# Get the list of user's
# environment variables
env_var = os.environ

# Print the list of user's
# environment variables
print("User's Environment variable:")
pprint.pprint(dict(env_var), width = 1)
4 changes: 4 additions & 0 deletions source/thanks.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
2023年
========

- 11月23日 ``**鹏`` 留言 "请喝咖啡 CloudAtlas @zgp"

**感谢**鹏** 支持,想到我撰写的技术分享能给大家带来帮助,鼓励我继续前行,多谢!

- 11月14日 ``*明`` 留言 "请喝咖啡 CloudAtlas @PretDB 鸟叔让我走的更近,奆佬让我看的更广!"

我刚开始学习Linux的时候,也在网上学习过鸟哥分享的技术文章,刚才google了一下,发现 `鳥哥的 Linux 私房菜 <https://linux.vbird.org>`_ 还在不断分享,向前辈致敬!
Expand Down

0 comments on commit 1fe4c47

Please sign in to comment.