Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Example Code - Named Pipes (Python 2.4 + ctypes on Windows)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul L. Du Bois  
View profile  
 More options Mar 25 2005, 2:59 pm
Newsgroups: comp.lang.python
From: "Paul L. Du Bois" <polyt...@gmail.com>
Date: 25 Mar 2005 11:59:31 -0800
Local: Fri, Mar 25 2005 2:59 pm
Subject: Re: Example Code - Named Pipes (Python 2.4 + ctypes on Windows)

Srijit Kumar Bhadra wrote:
> Hello,
> Here is an example of Multithreaded Pipe Server and Client using the
> excellent ctypes library (Windows).

Coincidentally, the other day I just used named pipes in for the first
time.  I recommend using the excellent win32api extension; I believe it
is included by deafult in the ActiveState distro.

The API calls look fairly similar, but you pass strings instead of
c_whatever_p(), they return tuples, and they throw exceptions instead
of returning HRESULT h s.t. FAILED(h).  The resulting code feels much
more Pythonic.  For example, my first test looked like this:

    def testread(self):
        """Read all data currently in pipe."""
        while True:
            try:
                (nRead, nAvail, nMessage) =
win32pipe.PeekNamedPipe(self.hFile, 0)
                if nAvail:
                    (hr, data) = win32file.ReadFile(self.hFile, nAvail)
                    return data
            except pywintypes.error, e:
                errno = e.args[0]
                if errno == 109:  # other end disconnected
                    self.disconnect()
                    self.connect()
                else:
                    raise

It's kind of cool that you can directly port C code to Python, but the
end result is IMO nigh-unreadable.

p


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.