Python:线程可以同时读/写到同一个 TCP 套接字吗? [英] Python : is it ok to threads read/write simultaneously to same TCP socket?

查看:26
本文介绍了Python:线程可以同时读/写到同一个 TCP 套接字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个读者线程&一个写线程到同一个 TCP 套接字.可以吗?在访问它之前我需要锁定吗?平台为 Windows 7,CPython 2.7.4

I want to have a reader thread & a writer thread to same TCP socket. Is it ok? Do I need to lock before accessing it ? Platform is Windows 7, CPython 2.7.4

推荐答案

对于 Unix 内核,两个线程对文件(套接字)的一个读取和另一个写入与两个进程执行相同的操作相同.由于内核能够对 IO 进行多路复用,因此您无需担心.

For Unix kernel two threads one reading and other writing to a file (socket) is same as two processes doing the same. As the kernel is capable of Multiplexing the IO you don't need to worry.

这篇关于Python:线程可以同时读/写到同一个 TCP 套接字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆