Problem with access to shared memory(W2K) / ORIGINALLY (win32) speedfan api control

Thomas Heller theller at python.net
Wed Apr 6 16:20:54 EDT 2005


"Claudio Grondi" <claudio.grondi at freenet.de> writes:

>> For the mistake you made see below, hope that helps.
> It doesn't.
>
>> >     pBuf_buf = cast(pBuf, Buffer)
>> Here's the problem.  pBuf is a pointer to a Buffer structure, not the
>> buffer structure itself.
>> Something like
>>     pBuf_buf = Buffer.from_address(pBuf)
>> may work.
> If I currently understand it right, cast() should
> do exactly this, i.e. should write the content
> pointed to by pBuf to a Python variable
> pBuf_buf which is an object of the Buffer
> class, where I can access the single
> components like any other Python
> variables - am I right or wrong?

You are right - my bad.
pBuf is a pointer to your structure, so:

ptr = cast(pBuf, POINTER(Buffer))
print ptr # should print <ctypes.LP_Buffer object at ...>
struct = ptr[0]

and now 'struct' should contain the data that you need.

>> For the general way to solve this problem you should know that you can
>> access a shared memory area with a certain name also with Python's mmap
>> module, although that is probably not documented very good.  There was a
>> recipe posted a few days ago which showed different ways to acces shared
>> memory, with or without ctypes.
>
>> > The code I use is provided also here:
>> >  http://www.codecomments.com/Python/message430495.html
>> >  http://mail.python.org/pipermail/python-list/2005-March/271853.html
>> > (the mmap part of it doesn't work at all)
>
> So I am already using the recipe, right?
> But it doesn't work as expected.
> mmap doesn't work at all failing in
> shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)
> with WindowsError: [Errno 87] wrong parameter

I get this error when I try to open a non-existing shared memory block.
>From the mmap docs: 

  If length is 0, the maximum length of the map is the current size of
  the file, except that if the file is empty Windows raises an exception
  (you cannot create an empty mapping on Windows).

If I run it with non-zero length it does not raise an exception

  shmem = mmap.mmap(0, 0, "$M$B$M$5$S$D$", mmap.ACCESS_READ)

although it *creates* the shared memory block, IIUC.  Are you sure your
speedfan app is running when you get the WindowsError?

Thomas



More information about the Python-list mailing list