473,809 Members | 2,742 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linux, fcntl, F_SETLEASE and signals

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.
import fcntl
f = open(".zshrc", "r+")
fcntl.fcntl(f, fcntl.F_SETLEAS E, fcntl.F_WRLCK)

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
--
Chris Green <cm*@dok.org>
You now have 14 minutes to reach minimum safe distance.
Jul 18 '05
11 2625
Jeff Epler <je****@unpytho nic.net> writes:
What I don't see here is any handling of threads.
You're right. I'm ignorant of the thread<->signal interaction in
python.

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_TH READS

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

Is this where you were recommending Py_AddPendingCa ll? 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
--
Chris Green <cm*@dok.org>
Warning: time of day goes back, taking countermeasures .

Jul 18 '05 #11
Jeff Epler <je****@unpytho nic.net> writes:
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.
--
Chris Green <cm*@dok.org>
A good pun is its own reword.
Jul 18 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2535
by: Meyer, Tony | last post by:
(I did try to google for an answer to this, but couldn't find anything, although plenty of instances of the warning). I don't understand this warning: >>> import fcntl C:\Program Files\Python23\lib\fcntl.py:7: DeprecationWarning: the FCNTL module is deprecated; please use fcntl DeprecationWarning) >>>
6
3835
by: Pierre Rouleau | last post by:
Hi all! I am using Python 2.3.1 on Win32 (NT, 2000). Whenever a file imports the standard tempfile module, Python 2.3.1 issues the following warning: C:\Python23\lib\fcntl.py:7: DeprecationWarning: the FCNTL module is Deprecated; please use fcntl DeprecationWarning).
0
1558
by: Ryan Grow | last post by:
Hi, I'm trying to use fcntl to set an existing file descriptor to be nonblocking. This contrived example exhibits the behavior of python that is preventing me from doing this: import os, fcntl, FCNTL file = open("/tmp/testfd.txt", 'w')
3
7446
by: Math55 | last post by:
hi, i have this piece of code: --- #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <termios.h> #include <stdio.h> /* baudrate settings are defined in <asm/termbits.h>, which is
8
16393
by: Vivek Menon | last post by:
Hi, I am using a C program to write/read from a serial port. The writing part is working perfectly fine. However, I am not able to read the values correctly and display them. To debug this issue I am also seeing the values on minicom. Now I have used fcntl() function and then read refp = fcntl(fd, F_SETFL, 0); res = read(fd,buf,1024); /* Read the value sent on the serial port buf=0; /* set end of string, so we can printf */...
7
5244
by: hlubenow | last post by:
Hello, I'd like to check, if a single key is pressed on a Linux xterm. This code waits for a key to be pressed and returns the character: -------------------------------------------- #!/usr/bin/env python import sys
9
5433
by: mhearne808[insert-at-sign-here]gmail[insert-dot-he | last post by:
I'm having a number of problems with the fcntl module. First off, my system info: Mac OS X Darwin igskcicglthearn.cr.usgs.gov 8.10.1 Darwin Kernel Version 8.10.1: Wed May 23 16:33:00 PDT 2007; root:xnu-792.22.5~1/RELEASE_I386 i386 i386 Python 2.5.1 (built from source) OK, the weirdness:
5
2726
by: GHUM | last post by:
hello, in my application I am using hSem = win32event.CreateSemaphore (None, 1, 1,"stringincludinginterfaceandport") rt=win32event.WaitForSingleObject (hSem, 0) if rt != win32event.WAIT_TIMEOUT: really_do_start_my_app() else:
4
5516
by: The Doctor | last post by:
Hey people, I have two applications: the server, which creates a server socket, waits for a real-time signal, and if it receives one, it creates a client socket. The client, which will connect to the server. This will generate a real- time signal at the server, who will create a client socket for this client.
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10637
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10379
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9199
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3014
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.