相关疑难解决方法(0)

Python套接字缓冲

假设我想使用标准socket模块从套接字读取一行:

def read_line(s):
    ret = ''

    while True:
        c = s.recv(1)

        if c == '\n' or c == '':
            break
        else:
            ret += c

    return ret
Run Code Online (Sandbox Code Playgroud)

究竟发生了s.recv(1)什么?它每次都会发出系统调用吗?我想我应该添加一些缓冲,无论如何:

为了最好地匹配硬件和网络现实,bufsize的值应该是2的相对较小的幂,例如4096.

http://docs.python.org/library/socket.html#socket.socket.recv

但是编写高效且线程安全的缓冲似乎并不容易.如果我使用file.readline()怎么办?

# does this work well, is it efficiently buffered?
s.makefile().readline()
Run Code Online (Sandbox Code Playgroud)

python sockets buffering

21
推荐指数
3
解决办法
6万
查看次数

没有 selenium 或 xvfb 的 Firefox Headless 运行一个简单的 javascript

具体来说,我对运行 selenium、phantomjs、chrome 或任何类型的虚拟帧缓冲区(如 xvfb)不感兴趣。

从 v56 开始,可以通过:

firefox -headless
Run Code Online (Sandbox Code Playgroud)

是否有可能运行像这样简单的东西:

firefox -headless some.js | grep -ioh 'stackoverflow' | wc -l
Run Code Online (Sandbox Code Playgroud)

不考虑任何时间...... some.js:

location.href="https://stackoverflow.com"
console.log(document.body);
Run Code Online (Sandbox Code Playgroud)

除了查看https://github.com/saucelabs/foxdriver的源代码之外,我一直无法找到关于控制它的好答案:

?  /Users/jmunsch/Desktop/public_dev /Applications/FirefoxNightly.app/Contents/MacOS/firefox-bin -headless 'javascript:location.href="https://ebay.com"'
*** You are running in headless mode.
[OSVR] Failed to load OSVR Util library!
[OSVR] Failed to load OSVR Util library!
2017-12-13 18:25:23.147 plugin-container[81081:12271051] *** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xb93b, name = 'com.apple.tsm.portname'
See /usr/include/servers/bootstrap_defs.h for the error codes.
2017-12-13 18:25:23.148 plugin-container[81081:12271051] *** …
Run Code Online (Sandbox Code Playgroud)

python firefox

5
推荐指数
0
解决办法
634
查看次数

标签 统计

python ×2

buffering ×1

firefox ×1

sockets ×1