async notification handling w/o threads/polling (similiar to kill-hup)?

N

News123

Hi,

I'd like to notify python processes asynchronously.
at notification time a callback should be called

The solution should be working on linux and Windows.

I could add a wrapper to switch between a windows / linux implementation
though

If possible I'd like to avoid
- having to poll for an external event
- having to add a thread.
- changing my existing code

I thought about using signal and os.kill()
However windows does not to have SIGHUP , SIGUSR1 or SIGUSR2.
So I'm not sure, which signal I could use with windows.


Apart from that there's one minor problem with signals
which might speak against using signal
All blocking io calls might be interrupted, which is not desirable in my
case.

Do you have any suggestions for
Linux / WIndows or both?


#### example code with signals #################
#### a blocking io call here reading a named pipe
#### would be interrupted
import signal
a = 0
def handler(signum,frame):
global a
a += 1

signal.signal(signal.SIGUSR1,handler)
print "hi"
p = open("namedpipe")
while True:
v = p.read(2)
print "V:",a,len(v)
if len(v) != 2: break

print "var a changed, but read() was interrupted :-("


bye


N
 
N

News123

News123 said:
Hi,

I'd like to notify python processes asynchronously.
at notification time a callback should be called

The solution should be working on linux and Windows.

I could add a wrapper to switch between a windows / linux implementation
though

If possible I'd like to avoid
- having to poll for an external event
- having to add a thread.
Well having a blocking thread would be fine though. what I'd really want
to avoid is any polling.
 

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

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top