Skip to content

Instantly share code, notes, and snippets.

@mrknmc
Last active January 14, 2020 19:57
Show Gist options
  • Save mrknmc/06cabb2d4187ea3180a0416fa39f7c82 to your computer and use it in GitHub Desktop.
Save mrknmc/06cabb2d4187ea3180a0416fa39f7c82 to your computer and use it in GitHub Desktop.
$ docker run -it --entrypoint=/bin/bash datadog/agent
root@c2c1c5bb0c16:/# python
Python 3.7.4 (default, Dec 31 2019, 19:02:30)
[GCC 4.7.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> # create socket for receive
>>> sock_read = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
>>> sock_read.bind('/tmp/socket-test')
>>> # create socket for send
>>> sock_write = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
>>> sock_write.connect('/tmp/socket-test')
>>> sock_write.setblocking(0)
>>> # send until buffer full, not receiving
>>> sock_write.send(b'0' * 100000)
100000
>>> sock_write.send(b'0' * 100000)
100000
>>> sock_write.send(b'0' * 100000)
100000
>>> sock_write.send(b'0' * 100000)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BlockingIOError: [Errno 11] Resource temporarily unavailable
>>> exc = None
>>> try:
... sock_write.send(b'0' * 100000)
... except BlockingIOError as e:
... exc = e
...
>>> exc
BlockingIOError(11, 'Resource temporarily unavailable')
>>> isinstance(exc, socket.error)
True
>>> isinstance(exc, socket.timeout)
False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment