Communicate between two python app
<p>I have done two app's :</p>

<ol>
<li>The first one is a spider that extract all links from a website.<br></li>
<li>The second one  do some checks on each link sent by the first app.</li>
</ol>

<p>When the first app find a link, how can I send a notification or something else to the second app ?<br>
The second app must listen continuously the data sent by the first app.</p>

<p>I found few post speaking of <code>Queue</code> but I don't really understand how that work.</p>

<p>Can someone explain me with a simple exemple how to communicate between the two app ?</p>

<p>Thank's</p>

<p>There are all sorts of ways to accomplish inter-process communication, but by far the simplest is to use the filesystem.  Have your spider write it's output to a temp file. When it's finished, move it into a folder that your second process polls periodically and when it finds work, then process it.</p>

<p>The <code>spider</code> could like something like:</p>

<pre><code>import tempfile, os
tmpname = ''
with tempfile.NamedTemporaryFile(delete=False) as tmp:
    tmpname = tmp.name
    tmp.write("spider output....\n")
tgt = os.path.join('incoming', os.path.basename(tmpname))
os.rename(tmpname, tgt)
</code></pre>

<p>The second process could look something like this:</p>

<pre><code>import time, os
while 1:
    time.sleep(5)
    for item in os.listdir('incoming'):
        work_item = os.path.join('incoming', item)
        with open(work_item) as fin:
            # do something with item
        os.unlink(work_item)
</code></pre>

python multithreading python-2.7 queue