Planet DebugUself

November 13, 2019

蠎周刊

Issue 394

俺的 Python 开发环境 2020 版

原文: PyCoder's Weekly - Issue #394

PyCoder

  • 191106 Zoom.Quiet(大妈) 用时 42 分钟 完成快译
  • 191106 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄.

The Python Software Foundation Packaging Working Group is receiving funding to work on the design, implementation, and rollout of pip’s next-generation dependency resolver. Funding has been allocated to secure a senior developer and an intermediate developer, starting in December 2019 or January 2020. RFP open now through November 22.

The co-creator of Django explains his Python environment: “My setup pieces together pyenv, poetry, and pipx. It’s probably a tad more complex than is ideal for most Python users, but for the things I need, it’s perfect.” Related discussion on Hacker News.

(是也乎:

来了, 又来了, 每年更新最具有引战体质话题...

pipenv 被弃用非常明智... )

Python list comprehensions make it easy to create lists while performing sophisticated filtering, mapping, and conditional logic on their members. In this tutorial, you’ll learn when to use a list comprehension in Python and how to create them effectively.

(是也乎:

Comprehension

最讨巧也最容易滥用的技巧...

简单说:

在应该使用时

)

“Don’t be afraid to create new, more specific data types for your specific use cases. It’s okay to represent different data, used for different purposes, with different data structures, and makes later generalization easier!”

(是也乎:

毕竟 Python 内置的, 而对其它对象的分析, Python 生态中工具也是最多的...

所以, 嫑怕, 放心定制自己舒服的... )

In this tutorial, you will learn how to automatically detect natural disasters (earthquakes, floods, wildfires, cyclones/hurricanes) with up to 95% accuracy using Keras, Computer Vision, and Deep Learning.

GitHub has published its latest State of the Octoverse report which provides fascinating insights into the development industry.

(是也乎:

第一当然是 JAVA 了, 报告中还有其它有趣的结论:

谁是增长最快的语言? 哪个编辑器最受欢迎...

当然, 无论调查如何, 自己舒服的才是最好的.

)

“We needed a Python interpreter that can be shipped everywhere. You won’t believe what happened next!”

(是也乎:

简单说, 用专用工具来完成...别自己乱来... )

(是也乎:

除了 this 模块之外, 在各种领域都散落有官方一直没注意到的神奇模块, 当然, 多数都是和大数据相关的, pandas 插件, 数据清理/探索, 以及性能检测什么的...

值得逐一尝试体验...

)

(是也乎:

简单说 datetime 才是最好的选择. )

讨论

Discussions

NIL

文章,教程和嗯哼

Articles, Tutorials and Talks

Python lambdas are little, anonymous functions, subject to a more restrictive but more concise syntax than regular Python functions. Test your understanding on how you can use them better!

(是也乎:

真蟒 少见的随堂测试, 大家可以尝试一下看对 Lambda 应用场景理解的是否嗯哼

)

“In this episode, Kelly and Sean discuss plausible trends in machine learning, artificial intelligence, augmented and virtual reality, and data science that we may see in schools by 2024. We focus on 5 areas from microscale in the classroom to macro across the entire educational system.”

(是也乎:

未来的教育中, Python 应该什么样?

AI 将泛滥, 工具将更加丰富, 老师将更加无力, 学生自主行为必然得到越来越大的加强

)

Learn about coroutines in Python by example. More specifically, you’ll see how to handle coroutines using asyncio.

In this course, you’ll learn how to work with recursion in your Python programs by mastering concepts such as recursive functions and recursive data structures.

(是也乎:

Recursively

递归...其实, 至今见过最精巧的 Recursively 都是在 LISP 生态中...

)

Learn how to read Stata (.dta) files in Python and how to write a Stata file to CSV and Excel files.

A step-by-step walkthrough of how to set up a basic CRUD app with Vue and Flask.

(是也乎:

Flask 的热点关联一直很专业

)

Exploring a Tornado use case in low memory environment.

(是也乎:

Tornado 严格意义上并不是框架, 而是基础组件, 当然, 也可以独立使用, 所以, 在小内存环境中很得趣...

)

(是也乎:

叕一个模块依赖管理思路... 只是, 第三方没什么好说的, 一但定型都是固定的, 工程内部自制模块的管理才是困难点吧...

)

(是也乎:

等等, 这有什么好比较的? 关注方向都相反的吧...

)

(是也乎:

一半都是5年以上老框架了,,,,而且多数都是专注 RESTful API 生成的, 并不是通用 web 应用框架

)

好物

Interesting Projects, Tools and Libraries, Projects & Code

(是也乎:

SeleniumBase

首先, 还是得起一个完整的 浏览器哪...

)

(是也乎:

CLI 果然是最好的界面

)

(是也乎:

好是好, 可惜不存在哪..

)

(是也乎:

这真的稳定了, 那 C++ 老司机可就惨了...

)

(是也乎:

这就叫专注... pytest 的插件,专门管理一定失败的安全带.

$ pytest --quarantine
====== test session starts ======
...
collected 1380 items
added mark.xfail to 661 of 661 items from quarantine.txt

...

====== 719 passed, 661 xfailed in 300.51 seconds ======

)

📆🐍 活动/大会

Events, MeetUp 真的是全球线下活动组织中心

DAMA

❤️ Happy Pythonic ;-(大妈私人无责任播报)

第4期已上线, 为期6周;

191124 报名结束
191201 正式开课
200112 按时结束

是也乎

NN 3829

by Pythoneerm at November 13, 2019 03:42 AM

November 08, 2019

bambooooooom

记一次 Firefox WebSocket debug

我司经常会通过 WebSocket 来向前端实时传递大量信息,之前同事一直说 Firefox 下 WebSocket 传送的数据有丢失, 造成渲染有问题,而 Chrome 没问题。 同事一直没有能完全解决,一个是不确定如何稳定复现,另一个是因为 Firefox (最新的 70)中的 WebSocket 每次传输的 frame message 在 DevTools 里是看不到的。

Firefox 71 终于要可以看到 WebSocket messages 数据了。 现在可以先使用 Firefox Developer 版本试用了。

我在另一个项目里也遇到类似问题,但是我用打 log 的方式发现 frame message 并没有丢失,但是顺序错了。 所以下载更新了 Firefox Developer 版本后,即可查看并判断是从后端接收的数据顺序就是错的,还是前端的代码造成的。

有了这个 WS inspector 之后就一眼看得出来后端传输没有问题,那只能是前端代码有问题了。(其实想想 Chrome 也并没有问题,的确不可能是后端的锅…😅)

回到代码本身,我发现了一个值得怀疑的点,就是在 WS 的 onmessage event 中,第一步需要对获取的数据进行类型转换。

if (data instanceof Blob) {
  data = await new Response(data).arrayBuffer();
}
data = new TextDecoder('utf-8').decode(data);

首先前提是服务器返回的是二进制数据。然后在 WS 中可能获取到的是 BlobArrayBuffer。 所以如果获取的 data 是 Blob, 先转换成 ArrayBuffer,再统一转化成 String

也没有啥其他办法,只是多打几次 log 看输出的 pattern 后,我基本确认就是 Response.arrayBuffer 这一步骤出现问题。 这个函数本身返回的是 Promise,即使 await 后,会出现后一帧的数据比前一帧的数据提前完成返回的情况,并继续进行后续的数据处理所以导致渲染失败。 现在想想这个相当于异步操作,的确本来也不能保证顺序是对的。这个代码本来就写的不太对呢。

那么怎么 fix 呢?我重新去翻了下有关 WS 的文档,以及搜了下 Blob 转成 ArrayBuffer 有什么别的方法么,能保证顺序的。 我发现以前漏掉的 WS 的一个细节是 WebSocket.binaryType

也就是设置 WS 中以哪种类型返回二进制数据。原来默认是 Blob,可以直接设置成 ArrayBuffer。 也就是说,这一步转换其实应该让浏览器帮我直接完成,我可以预期我获得的 data 一定是 ArrayBuffer

在创建 WS 的时候加上这个设置,并去掉前面 Response.arrayBuffer 的调用后,在 Firefox 70 和 Firefox Developer 下都尝试了很多次,终于再也没有出现数据顺序错位的问题了。

至于为什么在 Chrome 下一直稳定没有问题,那大概就是他们各自内部对这个函数的实现细节上的差异,而我暂时并不知道这个细节差异是什么了。

by bambooom ([email protected]) at November 08, 2019 03:27 PM

November 06, 2019

li guang he

普宁2

妻子一剑斩下来的时候,普宁只听到了血喷出来的声音,剑够快,像风声一样好听。是胳膊,他想。‘不对,是小普宁’,妻子这样回道,‘我是你的欲望与快乐,你一直讨厌的事物。你一直在阉割你自己。’‘……’真想说她说的不对啊,但确实切中要害,无法反驳。

剑过于锋利,妻子自己

November 06, 2019 01:00 PM

蠎周刊

Issue 393

DROPBOX 官方致谢老爹6年贡献, 对比...

原文: PyCoder's Weekly - Issue #393

PyCoder

  • 191106 Zoom.Quiet(大妈) 用时 42 分钟 完成快译
  • 191106 Zoom.Quiet(大妈) 用时 17 分钟 完成格式转抄.

The CPython team moves to a consistent annual release schedule. More info here in PEP 602.

Learn how to build a mobile application with Python and the Kivy GUI framework. You’ll discover how to develop an application that can run on your desktop as well as your phone. Then, you’ll package your app for iOS, Android, Windows, and macOS.

(是也乎:

讲真, 用 QPython 更加简洁

)

“[We] aim to identify how the Python development world looks today and how it compares to the last two years. The results of the survey will serve as a major source of knowledge about the current state of the Python community and how it is changing over the years, so we encourage you to participate and make an invaluable contribution to this community resource. The survey takes approximately 10 minutes to complete.”

(是也乎:

官方构建的, 想更多引发对中国程序猿的注意, 大家多去填写吧

)

“Python 3 is great! But not every Python 2 project has to be migrated. There are different ways how you can prepare for the upcoming Python 2 End of Life.”

(是也乎:

无法同意更多, 绝大多数应用并没到只有 Py3 能承载的分儿上

)

Arguments for why you should always use python -m pip over pip/pip3 to control exactly which Python environment is used.

“After six and a half years, Guido van Rossum, the creator of Python, is leaving Dropbox and heading into retirement.”

(是也乎:

老爹, 多谢哉.

--> DROPBOX 官方致谢, 当然, 当年 Google 并没感谢过, 毕竟...你懂的

)

讨论

Discussions

NIL

文章,教程和嗯哼

Articles, Tutorials and Talks

What does Python 3.8 bring to the table? Learn about some of the biggest changes and see you how you can best make use of them.

(是也乎:

3.5 开始, Python 也学习 C# 开始堆新功能了...

)

How to view log output from Docker containers in an automated CI/CD system in your GitHub pull requests, using Elasticsearch and a Python REST API built with Sanic.

How to train your own traffic sign classifier/recognizer capable of obtaining over 95% accuracy using Keras and Deep Learning.

In Part 4 of this series, you’ll learn how to create a Single-Page Application (SPA) to interface with the REST API backend that you built in Part 3. Your SPA will use HTML, CSS, and JavaScript to present this REST API to a user as a browser-based web application.

A post-mortem of how Omer’s team tracked down and fixed a performance regression introduced by a switch from Celery to RQ.

(是也乎:

实例案例故事

)

MyPy assisted error handling, exception mechanisms in other languages, fun with pattern matching and type variance.

(是也乎:

是的, 不是飙版本号的 CPython, 而是 MyPy

)

Considering a filename and a line number, can you tell which function, method or class a line of code belongs to?

Microsoft announced Visual Studio Online, an online IDE and cloud-based development environment based on VS Code.

(是也乎:

VStudio 不是 VSCode 哪...

)

This tutorial shows how to manage static files with Flask, WhiteNoise, and Amazon CloudFront.

(是也乎:

为什么无人知晓?

)

好物

Interesting Projects, Tools and Libraries, Projects & Code

(是也乎:

Cookbook 一向是实在的经验汇集形式

)

(是也乎:

没有什么, 不能在 CLI 中嗯哼的...

)

📆🐍 活动/大会

Events, MeetUp 真的是全球线下活动组织中心

DAMA

❤️ Happy Pythonic ;-(大妈私人无责任播报)

第4期已开课, 为期6周;

191102 开始报名
191124 报名结束
191201 正式开课
200112 按时结束

是也乎

NN 3823

by Pythoneerm at November 06, 2019 03:42 AM