Linux, fcntl, F_SETLEASE and signals

C

Chris Green

Hey folks,

Is there anyway for a signal handler in python to get the information
from a 3 argument signal handler rather than just the signal number
and stack frame?

I've got an application where I have to check for F_SETLEASE on a file
in python on Linux 2.4. What this does is tells the kernel to notify
the current process with SIGIO that a particular file descriptor is being
modified by another process.
0

Now, when another process opens ".zshrc", I get a SIGIO saying
something happened. The kernel provides the information on what
descriptor changed in a siginfo_t's si_fd field.

Is there anyway to get this from python?

Thanks,
Chris
 
M

Michael Hudson

Chris Green said:
Hey folks,

Is there anyway for a signal handler in python to get the information
from a 3 argument signal handler rather than just the signal number
and stack frame?
No.

I've got an application where I have to check for F_SETLEASE on a file
in python on Linux 2.4. What this does is tells the kernel to notify
the current process with SIGIO that a particular file descriptor is being
modified by another process.

0

Now, when another process opens ".zshrc", I get a SIGIO saying
something happened. The kernel provides the information on what
descriptor changed in a siginfo_t's si_fd field.

Is there anyway to get this from python?

What a wonderful interface. I think you'll have to write some C for
this...

Cheers,
mwh
 
J

Jeff Epler

I don't know of a way to do this without an extension module. It should
be possible to do it with an extension module, though. The module
would use sigaction() to install its own handler for SIGIO, and stash
the desired fields from the siginfo_t parameter somewhere. Use
Py_AddPendingCall() (undocumented? but with a public API name) to run a
callback with the stashed information in the void* arg, which calls back
into Python or does whatever else you need.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFA/p61Jd01MZaTXX0RAjKJAKCXL47MW0LwZJyKcjqObHwtq1cxYACfZgRB
0yObNIGu/VE3Bk8cwVRE/hI=
=Ye8Y
-----END PGP SIGNATURE-----
 
J

John Lenton

Hey folks,

Is there anyway for a signal handler in python to get the information
from a 3 argument signal handler rather than just the signal number
and stack frame?

I've got an application where I have to check for F_SETLEASE on a file
in python on Linux 2.4. What this does is tells the kernel to notify
the current process with SIGIO that a particular file descriptor is being
modified by another process.

0

would this be close enough?

Python 2.3.4 (#2, Jul 5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information..... I/O possible
 
J

John Lenton

Hey folks,

Is there anyway for a signal handler in python to get the information
from a 3 argument signal handler rather than just the signal number
and stack frame?

I've got an application where I have to check for F_SETLEASE on a file
in python on Linux 2.4. What this does is tells the kernel to notify
the current process with SIGIO that a particular file descriptor is being
modified by another process.

0

would this be close enough?

Python 2.3.4 (#2, Jul 5 2004, 09:15:05)
[GCC 3.3.4 (Debian 1:3.3.4-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.... I/O possible

sorry, I got the wrong end of the stick. But ctypes lets you do what
you want, anyways. Portable as Linux :)
 
G

Gardner Pomper

Hi,

I am not sure if this is the right list, but I am having a problem with
the installation of boa constructor. It all seems to have installed with
no errors, but when I try to run it, this is what I get:
python /usr/lib/python2.2/boa-constructor-0.2.3/Boa.py
Starting Boa Constructor v0.2.3
importing wxPython
reading user preferences
Segmentation fault

Here is how I installed it:


I went to boa-constructor.sourceforge.net and went to the download area.
There it says:

Before this can work, you'll need to have successfully installed
wxPython 2.4.0.7 or higher and Python 2.1 or higher. I have listed my
installed versions below.

Here is the list of my installed versions of python related things:

rpm -qa | grep -i python
python-2.2.3-5
mod_python-3.0.3-2.ent
gnome-python2-bonobo-1.99.14-5
gnome-python2-1.99.14-5
libxml2-python-2.5.10-5
bproc-python-0.9-13_Scyld
wxPythonGTK-py2.2-2.5.1.5-1
python-optik-1.4.1-2
gnome-python2-gtkhtml2-1.99.14-5
python-devel-2.2.3-5
gnome-python2-gconf-1.99.14-5
rpm-python-4.2.1-4.4
gnome-python2-canvas-1.99.14-5

Here is my list of gtk related things:

rpm -qa | grep -i gtk
gtk2-2.2.4-4.0
pygtk2-libglade-1.99.16-8
gtkhtml2-devel-2.2.0-6
pygtk2-devel-1.99.16-8
gtkhtml2-2.2.0-6
gtkam-0.1.7-6
gtkhtml3-3.0.9-4
gtk2-engines-2.2.0-2
gtk2-devel-2.2.4-4.0
gtk-doc-1.1-3.0
gtk+-1.2.10-27.1
pygtk2-1.99.16-8
gtk-engines-0.12-2.0
gtk+-devel-1.2.10-27.1
wxPythonGTK-py2.2-2.5.1.5-1
gnome-python2-gtkhtml2-1.99.14-5
gtkam-gimp-0.1.7-6
usermode-gtk-1.68-5

I downloaded boa-constructor-0.2.3.src.zip and unzipped it as root in
the /usr/lib/python2.2 directory.

Can anyone give me any suggestions on what to try next?

- Gardner
 
C

Chris Green

John Lenton said:
sorry, I got the wrong end of the stick. But ctypes lets you do what
you want, anyways. Portable as Linux :)

Thanks for pointing me to that. Seems like a very interesting
module. It may help me out :)
 
V

vincent wehren

Gardner said:
Hi,

I am not sure if this is the right list, but I am having a problem with
the installation of boa constructor. It all seems to have installed with
no errors, but when I try to run it, this is what I get:



Starting Boa Constructor v0.2.3
importing wxPython
reading user preferences
Segmentation fault

Here is how I installed it:


I went to boa-constructor.sourceforge.net and went to the download area.
There it says:

Before this can work, you'll need to have successfully installed
wxPython 2.4.0.7 or higher and Python 2.1 or higher. I have listed my
installed versions below.

Here is the list of my installed versions of python related things:

rpm -qa | grep -i python
python-2.2.3-5
mod_python-3.0.3-2.ent
gnome-python2-bonobo-1.99.14-5
gnome-python2-1.99.14-5
libxml2-python-2.5.10-5
bproc-python-0.9-13_Scyld
wxPythonGTK-py2.2-2.5.1.5-1
python-optik-1.4.1-2
gnome-python2-gtkhtml2-1.99.14-5
python-devel-2.2.3-5
gnome-python2-gconf-1.99.14-5
rpm-python-4.2.1-4.4
gnome-python2-canvas-1.99.14-5

Here is my list of gtk related things:

rpm -qa | grep -i gtk
gtk2-2.2.4-4.0
pygtk2-libglade-1.99.16-8
gtkhtml2-devel-2.2.0-6
pygtk2-devel-1.99.16-8
gtkhtml2-2.2.0-6
gtkam-0.1.7-6
gtkhtml3-3.0.9-4
gtk2-engines-2.2.0-2
gtk2-devel-2.2.4-4.0
gtk-doc-1.1-3.0
gtk+-1.2.10-27.1
pygtk2-1.99.16-8
gtk-engines-0.12-2.0
gtk+-devel-1.2.10-27.1
wxPythonGTK-py2.2-2.5.1.5-1
gnome-python2-gtkhtml2-1.99.14-5
gtkam-gimp-0.1.7-6
usermode-gtk-1.68-5

I downloaded boa-constructor-0.2.3.src.zip and unzipped it as root in
the /usr/lib/python2.2 directory.

Can anyone give me any suggestions on what to try next?

- Gardner


AFAIK, Boa doesn't work with wxPython 2.5.1. With Boa, you need to use
wxPython 2.4.2.
 
C

Chris Green

Jeff Epler said:
Use Py_AddPendingCall() (undocumented? but with a public API name) to
run a callback with the stashed information in the void* arg, which
calls back into Python or does whatever else you need.

What I ended up doing what creating a module that just installed a
handler that appends FD info onto a queue and then have a python call
that will check that queue suitable for use in an event loop.

It's my first python C extension so there's a few things I'm sure I'm
not doing right, most notably finding the spot to put finalization
code in.

http://cmg.dok.org/cgi-bin/pyblosxom.cgi/python/linuxlease
 
J

Jeff Epler

What I don't see here is any handling of threads.

The SIGIO handler might be called at the same time as Python code is
running in another thread. That means the call to getPending can see a
partially modified queue, or that the queue can be modified by a signal
while getPending is running.

Perhaps the code is written in some way that avoids these problems, but
I wasn't able to see how that would happen.

Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQFBBRQNJd01MZaTXX0RAuUGAKCCe7jFNJFEXR6BpUPMw9mJb9w5qACfdYEM
GmMXiEf+ZZ9osszXIr6M5j0=
=FgXB
-----END PGP SIGNATURE-----
 
C

Chris Green

Jeff Epler said:
What I don't see here is any handling of threads.


The SIGIO handler might be called at the same time as Python code is
running in another thread. That means the call to getPending can see a
partially modified queue, or that the queue can be modified by a signal
while getPending is running.

If I put a thread-safe mutex around the queue, that should be good
enough? Everything that I've seen has

Py_BEGIN_ALLOW_THREADS
code
Py_END_ALLOW_THREADS

getPending()
read from queue
interrupt while reading via signal
read from modified queue

Is this where you were recommending Py_AddPendingCall? Add the
pending increment when no other fields are taking place?

Are C extensions only accessed by a single thread unless they
Py_BEGIN_ALLOW_THREADS?

Thanks,
Chris
 
C

Chris Green

Jeff Epler said:
What I don't see here is any handling of threads.

http://cmg.dok.org/code/linuxlease-0.3.tar.gz now has the same signal
code roughly as signalmodule.c. The biggest difference is that I
add to my internal queue the pending calls with an argument of a
pointer to the signal handler argument.

I'm not sure that is safe but it seems to work. Ideally, I'd
allocate space for the argument and then queue it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top