Interprocess communication

J

Jonas Galvez

I have a Python script running as daemon. I need a way to have a Ruby
script send a message to it and read a response. I've been reading
about pipes and fifo but it's all very confusing.

Just thought I'd ask before trying anything: what's the safest and
easiest way to accomplish this in Ruby?

--Jonas Galvez
 
R

Robert Klemme

Jonas said:
I have a Python script running as daemon. I need a way to have a Ruby
script send a message to it and read a response. I've been reading
about pipes and fifo but it's all very confusing.

Just thought I'd ask before trying anything: what's the safest and
easiest way to accomplish this in Ruby?

Depends on which changes you can do to the python script. Does it offer
some kind of messaging functionality already?

If you can start from scratch (for example because you have to change the
phython script anyway) you can do any of these:

- make the python script open a pair of named pipes, one for reading and
one for writing answers. This works good only if you do have just a
single client (your ruby script)

- make the phython script open a unix domain socket (which is accessible
only from localhost). That way you can have several clients connect but
your phython script must handle these.

- dedicate a directory for exchange of messages via files. You then need
some kind of locking and a protocol, who writes which files there etc.

It really depends on your situation and requirements. If you provide more
input we might be able to come up with a more concrete suggestion.

Kind regards

robert
 
D

Dido Sevilla

I have a Python script running as daemon. I need a way to have a Ruby
script send a message to it and read a response. I've been reading
about pipes and fifo but it's all very confusing.
=20
Just thought I'd ask before trying anything: what's the safest and
easiest way to accomplish this in Ruby?

The simplest (not necessarily the best, that would on your
application's exact requirements, of which you've given us few
details), I think, would be to use XML-RPC. There are mature and
well-tested XML-RPC libraries for both Ruby and Python (for Python, I
believe it's integrated into the language's standard libraries
already). Set your Python script to be an XML-RPC server, and Ruby to
be your XML-RPC client and off you go. This ought to work even if your
Ruby and Python scripts are running on different computers, but it's a
fairly heavyweight approach.
 
L

Lyndon Samson

The simplest (not necessarily the best, that would on your
application's exact requirements, of which you've given us few
details), I think, would be to use XML-RPC. There are mature and
well-tested XML-RPC libraries for both Ruby and Python (for Python, I
believe it's integrated into the language's standard libraries
already). Set your Python script to be an XML-RPC server, and Ruby to
be your XML-RPC client and off you go. This ought to work even if your
Ruby and Python scripts are running on different computers, but it's a
fairly heavyweight approach.
=20

You could of course use the principles of OO and abstract that away,
perhaps providing a shared memory impl as well as the XML-RPC.




--=20
Into RFID? www.rfidnewsupdate.com Simple, fast, news.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top