From: News123 on
News123 wrote:
> 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.
> - 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