Skip to content

Instantly share code, notes, and snippets.

View NicolasT's full-sized avatar

Nicolas Trangez NicolasT

View GitHub Profile
@NicolasT
NicolasT / nonblocking.py
Last active February 11, 2024 19:15
Using the 'splice' syscall from Python, in this demonstration to transfer the output of some process to a client through a socket, using zero-copy transfers. See 'splice.py'. Usage: 'python splice.py' in one console, then e.g. 'nc localhost 9009' in another. 'nonblocking.py' is a demonstration of using 'splice' with non-blocking IO.
'''
Demonstration of using `splice` with non-blocking IO
Lots of code is similar to 'splice.py', take a look at that module for more
documentation.
'''
import os
import os.path
import errno
# <License type="Sun Cloud BSD" version="2.2">
#
# Copyright (c) 2005-2009, Sun Microsystems, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# Some code to retrieve CPUID information in pure Python
#
# Copyright (C) 2009 Nicolas Trangez <eikke eikke com>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation, version 2.1
# of the License.
#
# This library is distributed in the hope that it will be useful,