<tfoot id='U0QBr'></tfoot>
    <legend id='U0QBr'><style id='U0QBr'><dir id='U0QBr'><q id='U0QBr'></q></dir></style></legend>

      <i id='U0QBr'><tr id='U0QBr'><dt id='U0QBr'><q id='U0QBr'><span id='U0QBr'><b id='U0QBr'><form id='U0QBr'><ins id='U0QBr'></ins><ul id='U0QBr'></ul><sub id='U0QBr'></sub></form><legend id='U0QBr'></legend><bdo id='U0QBr'><pre id='U0QBr'><center id='U0QBr'></center></pre></bdo></b><th id='U0QBr'></th></span></q></dt></tr></i><div id='U0QBr'><tfoot id='U0QBr'></tfoot><dl id='U0QBr'><fieldset id='U0QBr'></fieldset></dl></div>

      <small id='U0QBr'></small><noframes id='U0QBr'>

      • <bdo id='U0QBr'></bdo><ul id='U0QBr'></ul>

      写入 UDP 套接字会阻塞吗?

      时间:2023-09-28
      <tfoot id='WoeKX'></tfoot>
        <bdo id='WoeKX'></bdo><ul id='WoeKX'></ul>
        1. <small id='WoeKX'></small><noframes id='WoeKX'>

            <tbody id='WoeKX'></tbody>

          1. <legend id='WoeKX'><style id='WoeKX'><dir id='WoeKX'><q id='WoeKX'></q></dir></style></legend>

          2. <i id='WoeKX'><tr id='WoeKX'><dt id='WoeKX'><q id='WoeKX'><span id='WoeKX'><b id='WoeKX'><form id='WoeKX'><ins id='WoeKX'></ins><ul id='WoeKX'></ul><sub id='WoeKX'></sub></form><legend id='WoeKX'></legend><bdo id='WoeKX'><pre id='WoeKX'><center id='WoeKX'></center></pre></bdo></b><th id='WoeKX'></th></span></q></dt></tr></i><div id='WoeKX'><tfoot id='WoeKX'></tfoot><dl id='WoeKX'><fieldset id='WoeKX'></fieldset></dl></div>

                本文介绍了写入 UDP 套接字会阻塞吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如果是这样,在什么条件下?或者,换一种说法,在 twisted 中运行这段代码是否安全:

                And if so, under what conditions? Or, phrased alternately, is it safe to run this code inside of twisted:

                class StatsdClient(AbstractStatsdClient):
                  def __init__(self, host, port):
                    super(StatsdClient, self).__init__()
                    self.addr = (host, port)
                    self.server_hostname = socket.gethostname()
                    self.udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
                
                  def incr(self, stat, amount=1):
                    data = {"%s|c" % stat: amount}
                    self._send(data)
                
                  def _send(self, data):
                    for stat, value in data.iteritems():
                      self.udp_sock.sendto("servers.%s.%s:%s" % (self.server_hostname, stat, value), self.addr)
                

                推荐答案

                是的,奇怪的是,UDP 套接字可以阻塞.

                Yes, oddly, a UDP socket can block.

                发生这种情况的条件基本上是,某处的某些缓冲区已满,您的操作系统决定是时候阻止某些东西了.这些可以说是内核错误,但我到处都看到过它们.有时在晦涩难懂、无法重现的条件下,您绝对可以得到 EWOULDBLOCK.

                The conditions under which this can happen are basically, some buffers somewhere fill up, your operating system decides it's time for something to block. These are arguably kernel bugs, but I've seen them here and there. You can definitely get EWOULDBLOCK sometimes under obscure, impossible-to-reproduce conditions.

                为什么要在 Twisted 中执行此操作,而不是使用 Twisted 的内置 UDP 支持 虽然?

                Why would you want to do this in Twisted instead of using Twisted's built-in UDP support though?

                这篇关于写入 UDP 套接字会阻塞吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 Python 中读取 UDP 数据包的缓冲区大小 下一篇:Python struct.pack() 用于列表中的单个元素?

                相关文章

                <tfoot id='g9sT8'></tfoot>
                  1. <small id='g9sT8'></small><noframes id='g9sT8'>

                    • <bdo id='g9sT8'></bdo><ul id='g9sT8'></ul>
                    <legend id='g9sT8'><style id='g9sT8'><dir id='g9sT8'><q id='g9sT8'></q></dir></style></legend>

                  2. <i id='g9sT8'><tr id='g9sT8'><dt id='g9sT8'><q id='g9sT8'><span id='g9sT8'><b id='g9sT8'><form id='g9sT8'><ins id='g9sT8'></ins><ul id='g9sT8'></ul><sub id='g9sT8'></sub></form><legend id='g9sT8'></legend><bdo id='g9sT8'><pre id='g9sT8'><center id='g9sT8'></center></pre></bdo></b><th id='g9sT8'></th></span></q></dt></tr></i><div id='g9sT8'><tfoot id='g9sT8'></tfoot><dl id='g9sT8'><fieldset id='g9sT8'></fieldset></dl></div>