V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  ray1888  ›  全部回复第 9 页 / 共 10 页
回复总数  194
1  2  3  4  5  6  7  8  9  10  
2017-07-06 11:03:42 +08:00
回复了 ray1888 创建的主题 Linux Linux 笔记本求推荐(预算 5000 左右)
@ifane 小米版是指小米笔记本吗?
2017-07-06 10:15:00 +08:00
回复了 ray1888 创建的主题 Linux Linux 笔记本求推荐(预算 5000 左右)
@chinanala 屏幕会很小吗?新公司没有显示器配,只能用自带笔记本屏幕
2017-07-06 10:13:57 +08:00
回复了 ray1888 创建的主题 Linux Linux 笔记本求推荐(预算 5000 左右)
@gdzzzyyy 有些会有硬件驱动不兼容神马的问题,想我现在的神舟游戏本,装 linux wifi 驱动会有问题,经常掉线
2017-07-05 10:37:26 +08:00
回复了 4ever911 创建的主题 Linux X1 Carbon 2017 真是难得的好 Linux 本
如果跟 xps13 那个比较好?续航时间那些
2017-06-21 11:05:45 +08:00
回复了 ray1888 创建的主题 Python Python 多进程问题
Multiprocessing.JoinableQueue 的 empty 方法只返回 True 和 False,没有 exception 产生
2017-06-21 10:05:51 +08:00
回复了 cyberdaemon 创建的主题 Android 夏天快到了,手机天天发烧。。。。
换小米 6 吧。。。如果真的想用安卓的话,如果感觉自己人品不错的话搏一搏荣耀 v9 也是可以的
2017-06-21 09:17:12 +08:00
回复了 ray1888 创建的主题 Python Python 多进程问题
@araraloren 其实如果 V2 可以像 stackoverFlow 上面那样,一键把代码全部格式化,那挺好的
2017-06-20 20:22:22 +08:00
回复了 ray1888 创建的主题 Python Python 多进程问题
@EchoUtopia 你的理解是对的。我刚刚认真看了官方文档也是类似这样描述的。翻译不太好,但是意思跟你的理解差不多。

task_done()
Indicate that a formerly enqueued task is complete. Used by queue consumer threads. For each get() used to fetch a task, a subsequent call to task_done() tells the queue that the processing on the task is complete.
If a join() is currently blocking, it will resume when all items have been processed (meaning that a task_done() call was received for every item that had been put() into the queue).
Raises a ValueError if called more times than there were items placed in the queue.
表明之前入队的任务完成(即现在出栈的任务)。使用队列消费者线程。当每个 get 方法获取一个任务,随后调用 task_done 告诉队列 运行在那个线程上的任务已经完成
当线程当前拥塞,当所有任务(个体)完成处理后,会继续(意味着 task_done 回调 是接收每个个体(任务)被放置到队列里面)
当被调用的次数多余队列中的个体数,会提出 Raise ValueError 值错误。
join()
Block until all items in the queue have been gotten and processed.
The count of unfinished tasks goes up whenever an item is added to the queue. The count goes down whenever a consumer thread calls task_done() to indicate that the item was retrieved and all work on it is complete. When the count of unfinished tasks drops to zero, join() unblocks.
阻塞直到队列里面所有的任务(个体)被获取并且被处理。
当队列里面被放入一个个体(任务)时,未完成任务数会+1,这个计数会随着一个消费进程调用 Task_done 去表示那个个体(任务)已经被取回,并且所有的队列里面的任务都已经完成。当未完成计数=0 时,队列不在阻塞
2017-06-20 18:00:38 +08:00
回复了 ray1888 创建的主题 Python Python 多进程问题
@EchoUtopia 这个可以了,想请问一下,我看了文档还是不太懂那个 task_done 的函数作用
2017-06-20 17:58:18 +08:00
回复了 ray1888 创建的主题 Python Python 多进程问题
@EchoUtopia 不行,还是会阻塞
2017-06-20 16:45:11 +08:00
回复了 ray1888 创建的主题 Python Python 多进程问题
import multiprocessing

def printt(q):
if q.empty():
pass
else:
data = q.get()
print data

if __name__ == "__main__":
q = multiprocessing.JoinableQueue()
for i in range(5):
q.put()
while 1:
for i in range(3):
process = multiprocessing.Process(target=printt, arg=(q,))
process.start()
process.join()
q.join()

代码变形了,重新贴一遍
2017-06-15 20:03:39 +08:00
回复了 ray1888 创建的主题 Python Python 的 socket 多线程问题,求大神解答
@noli 为什么我这段代码还是会报错,他说我并没有协程,但是我不知道问题在哪个地方
import socket
import asyncio

def waiting(sock):
sock.listen(5)
sock_acc, addr = sock.accept()
return sock_acc

async def sendhello(sendsock):
sendsock.send(b'100')
remote = sendsock.getsockname()
print("{} is connect".format(remote[0]))

async def createsock():
sock = socket.socket()
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('0.0.0.0', 8999))
sock_acc = waiting(sock)
await sendhello(sock_acc)


if __name__ == "__main__":
loop = asyncio.get_event_loop()
#task = [createsock() for i in range(5)]
#loop.run_until_complete(task)
task = [createsock(), createsock()]
loop.run_until_complete(task)
loop.close()

报错是这样的
sys:1: RuntimeWarning: coroutine 'createsock' was never awaited
2017-06-15 20:02:30 +08:00
回复了 ray1888 创建的主题 Python Python 的 socket 多线程问题,求大神解答
@noli 你好
2017-06-15 16:32:31 +08:00
回复了 ray1888 创建的主题 Python asyncio 的 await 回调需要的条件是什么?
@kindjeff 所以是 await 函数接的是 IO 操作对应的函数?不是很懂
2017-06-15 16:16:34 +08:00
回复了 ray1888 创建的主题 Python asyncio 的 await 回调需要的条件是什么?
@dishonest 其实就是想问 await 后面能接什么函数而已,如果打掉 11 行的 await,就相当于让渡之后拿到控制权的函数线性执行
2017-06-15 16:00:59 +08:00
回复了 ray1888 创建的主题 Python asyncio 的 await 回调需要的条件是什么?
1 import asyncio
2
3 def addone(x,y):
4 x = x+1
5 y = y+1
6 print("x={}".format(x))
7
8 async def compute(x, y):
9 print('Compute {} + {} ...'.format(x, y))
10 await asyncio.sleep(1.0)
11 #await addone(x,y)
12 return x + y
13
14 async def print_sum(x, y):
15 result = await compute(x, y)
16 print('{} + {} = {}'.format(x, y, result))
17
18 loop = asyncio.get_event_loop()
19 loop.run_until_complete(print_sum(1, 2))
20 loop.close()

这样就不会报错,那么我只能调用异步的函数吗?如果是,那如何知道哪些内置的函数支持异步?
2017-06-15 15:58:30 +08:00
回复了 ray1888 创建的主题 Python asyncio 的 await 回调需要的条件是什么?
帖子代码格式出了问题,我尝试重新贴一下
1 import asyncio
2
3 def addone(x,y):
4 x = x+1
5 y = y+1
6 print("x={}".format(x))
7
8 async def compute(x, y):
9 print('Compute {} + {} ...'.format(x, y))
10 #await asyncio.sleep(1.0)
11 await addone(x,y)
12 return x + y
13
14 async def print_sum(x, y):
15 result = await compute(x, y)
16 print('{} + {} = {}'.format(x, y, result))
17
18 loop = asyncio.get_event_loop()
19 loop.run_until_complete(print_sum(1, 2))
20 loop.close()

第一段的代码

报错如下:await addone(x,y) TypeError: object int can't be used in 'await' expression
2017-06-14 22:28:25 +08:00
回复了 ray1888 创建的主题 Python Python 的 socket 多线程问题,求大神解答
@noli 大神有好的 ASYNCIO 的模块教程或者项目推荐给我看吗?我看廖雪峰那个教程还是有点不太懂
2017-06-14 09:47:41 +08:00
回复了 ray1888 创建的主题 Python Python 的 socket 多线程问题,求大神解答
@AZLisme 那是否就是协程和多线程多进程不能并存吗?因为还是不太懂协程和多线程对于并发的区别。我目前所知的协程,是单个线程在不同时间内进行多个任务的执行,等待 await 返回的结果,如果同一程序多线程或多进程,就是相当于可以同时处理多个请求,但是程序是线性运行
2017-06-14 09:20:54 +08:00
回复了 ray1888 创建的主题 Python Python 的 socket 多线程问题,求大神解答
@noli 如果我用 Python3,gevent 和 asyncio 应该用哪一个来做协程?然后做了协程之后,还需要多开线程来处理吗?
1  2  3  4  5  6  7  8  9  10  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5867 人在线   最高记录 6543   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 21ms · UTC 06:24 · PVG 14:24 · LAX 23:24 · JFK 02:24
Developed with CodeLauncher
♥ Do have faith in what you're doing.