我正在实现一个Python脚本,需要在不到5秒的时间内并行发送1500多个数据包.
简而言之,我需要的是:
def send_pkts(ip):
#craft packet
while True:
#send packet
time.sleep(randint(0,3))
for x in list[:1500]:
send_pkts(x)
time.sleep(randint(1,5))
Run Code Online (Sandbox Code Playgroud)
我尝试过简单的单线程,多线程,多处理和多处理+多线程表单,并遇到以下问题:
有没有更好的方法可以用来完成这项任务?
[1]编辑1:
def send_pkt(x):
#craft pkt
while True:
#send pkt
gevent.sleep(0)
gevent.joinall([gevent.spawn(send_pkt, x) for x in list[:1500]])
Run Code Online (Sandbox Code Playgroud)
[2]编辑2(gevent monkey-patching):
from gevent import monkey; monkey.patch_all()
jobs = [gevent.spawn(send_pkt, x) for x in list[:1500]]
gevent.wait(jobs)
#for send_pkt(x) check [1]
Run Code Online (Sandbox Code Playgroud)
但是我收到以下错误:"ValueError:filedescriptor超出了select()"范围.所以我检查了我的系统ulimit(软和硬都是最大值:65536).之后,我检查了它与Linux 上的select()限制(最多1024 fds)有关.请检查:http://man7.org/linux/man-pages/man2/select.2.html(BUGS部分) - 为了解决这个问题,我应该使用poll()(http://man7.org/linux/ man-pages/man2/poll.2.html)相反.但是使用poll() …
一周前我正在运行Node.js和Node-RED(取决于Node.js).我的系统是Windows 8.1 64位.
不过,今天我遇到了一个问题:
通常,我转到node-red文件夹,然后运行节点red.js. 然后,令人惊讶的是我从提示中得到以下消息:
Node Commands
Syntax:
node {operator} [options] [arguments]
Parameters:
/? or /help - Display this help message.
list - List nodes or node history or the cluster
listcores - List cores on the cluster
view - View properties of a node
online - Set nodes or node to online state
offline - Set nodes or node to offline state
pause - Pause node [deprecated]
resume - Resume node [deprecated]
For more information about HPC command-line …Run Code Online (Sandbox Code Playgroud)