forum.vmspython.org Forum Index forum.vmspython.org
Forum system
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Sending signal from Fortran to Python

 
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS
View previous topic :: View next topic  
Author Message
Colin Brown



Joined: 11 Oct 2012
Posts: 18
Location: Wellington, NZ

PostPosted: Wed Oct 24, 2012 11:11 pm    Post subject: Sending signal from Fortran to Python Reply with quote

Does anyone know how to send a signal from within a Fortran AST routine that can be detected by a python signal.pause?

I have found the following link (Google "vms ptools") that seems to show that it can be done.

http://www2.tornqvist.eu/help?key=PTOOLS~API~PTOOLS$RAISE_ALARM&explode=yes&title=VMS%20Help&referer=http%3A//www2.tornqvist.eu/help%3Fkey%3DV73_Features%257EProgramming_Features%26explode%3Dyes%26title%3DVMS%25252520Help%26referer%3D
Back to top
View user's profile Send private message
bonzothecat



Joined: 15 Jan 2005
Posts: 24
Location: Sooke, BC, Canada

PostPosted: Mon Oct 29, 2012 5:19 pm    Post subject: Reply with quote

One way to do this might be to code a kill() statement (http://h71000.www7.hp.com/doc/732final/5763/5763pro_039.html) in a C module, then link to the module from your FORTRAN program.
_________________
Howard Taylor
Badger Consulting
Sooke, BC, Canada
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Colin Brown



Joined: 11 Oct 2012
Posts: 18
Location: Wellington, NZ

PostPosted: Tue Oct 30, 2012 1:16 am    Post subject: Reply with quote

Thanks for the hint. I managed to code a kill into a C shared exe that I
called from my Fortran shared exe that I accessed from a test python
script using ctypes. Unfortunately all the different signal types I tried
did not get caught by the python signal handler I implemented. The
signals were received by the python waiting on signal.pause but the
program simply terminated. Through implementing the above, I did view:

http://blip.tv/carlfk/mindblowing-python-gil-2243379

which got me to thinking that what I should use is a $waitfr in a ctypes
call running in my "output" thread while still allowing network triggered
code to run in my "input" thread (because the docs say "The Python global interpreter lock is released before calling any function exported by
these libraries, and reacquired afterwards.") It works! Other threads
continue while my shared EXE $waitfr waits pending the setting of an
event flag. I have other Fortran code that I run prior to the $waitfr
that sets the event flag on receiving a "signal" via a lock-blocking AST.
Simple really.

Yes, I know there is a "waitef" in vms.starlet, but it does not release
the GIL so other threads can process.
Back to top
View user's profile Send private message
bonzothecat



Joined: 15 Jan 2005
Posts: 24
Location: Sooke, BC, Canada

PostPosted: Tue Oct 30, 2012 4:42 pm    Post subject: Reply with quote

Good for you, Colin, that sounds like an excellent solution. It will likely continue to work correctly even as Python and the CRTL evolve and change.

Cheers,
_________________
Howard Taylor
Badger Consulting
Sooke, BC, Canada
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    forum.vmspython.org Forum Index -> Python for OpenVMS All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group