>>> YieldNull
  • /blog
  • /archives
  • /github
  • /about

Entries tagged with Python

  • 使用Python子进程,你处理这两种情况了吗?

    2019-10-27 20:33:04 / Python /6550 hits

    CPython由于GIL的存在,Python服务端程序通常在子进程中处理请求。使用子进程时,可能会遇到以下两种情况:

    • 子进程结束后变成僵尸进程,占用进程号。
    • 子进程占用父进程LISTEN的端口号,导致父进程重启时失败。

    下文将在docker python:2.7环境下,模拟一种服务端场景,以复现这两个问题,并提出解决方案。

    Read more...


  • 利用进程、线程、协程并发执行任务

    2017-10-05 17:20:57 / CS Python /5171 hits

    Screen Shot 2017-10-05 at 15.41.26

    Read more...


  • Python3 Truth Value Testing and Boolean Operations

    2017-05-29 23:49:13 / Python /3992 hits

    之前一直以为Python中and、or 这两个表达式的返回值是True 或者 False,今早帮同学解答问题时才发现之前的理解是错误的。

    Read more...


  • Supervisor+Gunicorn+Flask 上传文件的编码问题

    2016-03-27 03:14:44 / Python Ubuntu /9111 hits

    使用Flask+Gunicorn+Supervisor+Nginx把应用部署到服务器时,出现了编码问题。

    File "/srv/www/biu/venv/lib/python3.4/site-packages/werkzeug/datastructures.py", 
    
    line 2653, in save
        dst = open(dst, 'wb')
    
    UnicodeEncodeError: 'ascii' codec can't encode characters
    
     in position 56-60: ordinal not in range(128)
    

    文件名的确有中文,但是在本地测试的时候没有问题啊!在本地采用的是'UTF-8'进行编码,但是在服务器怎么就是'ASCII'了?

    Read more...


  • 备份QQ空间说说

    2015-11-17 23:24:50 / Python /5348 hits

    先将Cookie及用户写入config.json中,格式如下

    {
        "shuoshuo":"<shuoshuo_cookie>",
        "friends":"<friends_cookie>",
        "user":"<your_qq_number>",
        "host_user":"<the_owner_qq>"
    }
    

    然后

    python shuoshuo.py config.json
    

    示例

    Read more...


  • Backup Neteasy Blog (备份网易博客)

    2015-10-26 20:37:57 / Python /5068 hits

    Backup your neteasy blog entries to a sqlite3 database.

    Only Created time,title and content are stored.

    Usage: neteasy.py <username>

    The <username> is your blog name which appears in your blog domain. Just like "junjie.blog.163.com", in which "junjie" is the <username>

    If everything is normal, the output will be like this:

    normal.png

    Read more...


  • Build A Website With Python-Flask and Nginx

    2015-10-24 16:30:56 / Python /6251 hits

    我們使用Nginx作爲前端反向代理服務器,一些靜態資源可以直接通過Nginx訪問。對於動態資源,Nginx將請求轉發到後端的Gunicorn服務器,Gunicorn負責調用後端的Python代碼,進行動態處理。

    上面,我們說道,nginx將動態請求轉發到本地的9000端口,Gunicorn正是監聽此端口。Nginx可以直接作爲服務進程啓動,但是Gunicorn還不行,因此我們使用Supervisor。Supervisor是一个管理进程的工具,可以随系统启动而启动服务,它还时刻监控服务进程,如果服务进程意外退出,Supervisor可以自动重启服务。同時,我們安裝gevent,它是一個把Python同步代码变成异步协程的库;

    Read more...


  • Shadow copy and Deep copy in Python

    2015-10-23 00:37:43 / Python /5352 hits

    Assignment statements in Python do not copy objects, they create bindings between a target and an object. For collections that are mutable or contain mutable items, a copy is sometimes needed so one can change one copy without changing the other.

    Read more...


  • WHUer计算成绩

    2015-09-29 12:46:57 / Python /4779 hits

    昨天有人问我关于奖学金评选的综合成绩是多少,当时我还没算。作为一名程序员当然不能用手工计算啦。不如写个程序从教务系统爬取成绩然后计算吧!

    Read more...


  • 爬取微博相册并下载到本地

    2015-04-13 01:17:02 / Python /8904 hits

    weitu.py Record

    起因

    清明节闲得无聊,想找些美女图片看看,于是想到用python爬微博图片

    经过

    登录新浪微博

    尼玛登录都需要rsa加密神马的,不知道怎么搞,上网搞的代码

    获取相册信息

    原以为只要GET到相册首页就可以用正则表达式提取相册URL的,把GET到的源代码下载到本地打开一看,我勒个擦,居然显示个正在加载!!!

    没想到尼玛居然使用JS加载的图片。

    用Chrome单步调试,发现了一个诡异的JSON文件,点开一看,我勒个擦,相册信息居然全在里面!

    Read more...


  • « Previous
  • Next »

About this site © YieldNull,