Interprocess communication in Python
The multiprocessing
library provides listeners and clients that wrap sockets and allow you to pass arbitrary python objects.
Your server could listen to receive python objects:
from multiprocessing.connection import Listener
address = ('localhost', 6000) # family is deduced to be 'AF_INET'
listener = Listener(address, authkey=b'secret password')
conn = listener.accept()
print 'connection accepted from', listener.last_accepted
while True:
msg = conn.recv()
# do something with msg
if msg == 'close':
conn.close()
break
listener.close()
Your client could send commands as objects:
from multiprocessing.connection import Client
address = ('localhost', 6000)
conn = Client(address, authkey=b'secret password')
conn.send('close')
# can also send arbitrary objects:
# conn.send(['a', 2.5, None, int, sum])
conn.close()
Interprocess communication between independent Python3 scripts
Take a look at the section on "Listeners and Clients" in the multiprocessing
docs; unlike the higher level simpler APIs, these APIs allow you to establish connections by address and authenticate the paired process, which allows two Python scripts to cooperate without having a parent/child relationship.
Interprocess communication with a modified python interpreter
Going with the other answer of mine turned out to be a mistake. Because of how handles are inherited in python2 on Windows I couldn't get the same solution to work on Windows machines. I ended up using the far superior Listener
and Client
interfaces also found in the multiprocessing module.
This question of mine discusses that mistake.
simple inter-process communication
In general you are interested in sockets. A good place to get just the needed rough information is the documentation of IO::Socket::INET or more basic socket-stuff in perl from perldoc perlipc
Related Topics
In Python, How to Read the Exif Data for an Image
In Python, How to Convert a 'Datetime' Object to Seconds
R and Python in One Jupyter Notebook
R Expand.Grid() Function in Python
How to Find Children of Nodes Using Beautifulsoup
Does Anybody Know How to Identify Shadow Dom Web Elements Using Selenium Webdriver
Convert HTML Entities to Unicode and Vice Versa
Python Multiprocessing Linux Windows Difference
How to Automatically Install Required Packages from a Python Script as Necessary
Detect Socket Hangup Without Sending or Receiving
Basic Python Hello World Program Syntax Error
Differencebetween Installing a Package Using Pip VS. Apt-Get
How to Test the Membership of Multiple Values in a List
Truth Value of a String in Python