Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'problem:': 0.07; 'satisfy': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'windows': 0.15; 'antoine': 0.16; 'be:': 0.16; 'descriptor': 0.16; 'fds': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'pointed': 0.19; 'written': 0.21; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'header :User-Agent:1': 0.23; "aren't": 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'received:24': 0.27; "doesn't": 0.30; '(like': 0.30; "i'm": 0.30; '-0700,': 0.31; 'anonymous': 0.31; 'subject:other': 0.31; 'writes:': 0.31; 'file': 0.32; 'interface': 0.32; 'url:python': 0.33; 'created': 0.35; 'case,': 0.35; 'but': 0.35; 'there': 0.35; '14,': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'too': 0.37; 'two': 0.37; 'thank': 0.38; 'url:library': 0.38; 'anything': 0.39; 'help,': 0.39; 'sure': 0.39; 'read': 0.60; 'url:3': 0.61; 'content-disposition:inline': 0.62; 'nobody': 0.68; 'facilities': 0.69; 'lack': 0.78; 'subject:read': 0.84; 'subject:Pair': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=nottheoilrig.com; s=mail; t=1376583592; bh=e/nMrtPvHTLWbhCSiY7DlEZP+INBPU82K3T6qI554ho=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:In-Reply-To; b=l16QkGyLcn55YRfi4zCxGi9p3O5IQg8gNZVbncNgK9oAGd3BxmeKrqyQBGSxlpQ82 Wgv5DgucgYc1yHdouqTp/rwFHYvpx8kyZ42r/dCpYHkeMDhA7BUoDoxOvTI7WJq+8M y1iQUJUBYz0/hchGRg7SdyAG1XklU4xH1gwIY+2I= Date: Thu, 15 Aug 2013 09:19:52 -0700 From: Jack Bates To: Antoine Pitrou Subject: Re: Pair of filenos read/write each other? References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1376583595 news.xs4all.nl 15886 [2001:888:2000:d::a6]:46492 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:52557 On Wed, Aug 14, 2013 at 08:34:36AM +0000, Antoine Pitrou wrote: > Nobody nowhere.com> writes: > > On Tue, 13 Aug 2013 16:10:41 -0700, Jack Bates wrote: > > > Is there anything like os.pipe() where you can read/write both ends? > > > > There's socket.socketpair(), but it's only available on Unix. > > > > Windows doesn't have AF_UNIX sockets, and anonymous pipes (like the ones > > created by os.pipe()) aren't bidirectional. > > I'm not sure I understand the problem: you can just create two pair of pipes > using os.pipe(). > If that's too low-level, you can wrap the fds using BufferedRWPair: > http://docs.python.org/3.3/library/io.html#io.BufferedRWPair > > (actual incantation would be: > r1, w1 = os.pipe() > r2, w2 = os.pipe() > > end1 = io.BufferedRWPair(io.FileIO(r1, 'r'), io.FileIO(w2, 'w')) > end2 = io.BufferedRWPair(io.FileIO(r2, 'r'), io.FileIO(w1, 'w')) > > end1.write(b"foo") > end1.flush() > end2.read(3) # -> return b"foo" > ) > > An alternative is to use multiprocessing.Pipe(): > http://docs.python.org/3.3/library/multiprocessing.html#multiprocessing.Pipe > > In any case, Python doesn't lack facilities for doing what you want. Thank you for your help, I need to satisfy an interface that requires a single file descriptor number that can be both read from and written to. Is it possible with any of the solutions you pointed out to get a single file descriptor number for each end?