title: Python file-based queue that is process-safe
body: <p>Is there a process safe persistent (disk-based) Python FIFO queue?</p>
  
  <p>Could someone provide a simple example with a script that writes a string to the queue, and another that reads one-string-at-a-time from the queue? Note that each of these processes can be launched multiple times from the command line. I.e. multiple writers and multiple readers.</p>
  
  <p><strong>Background</strong>: I have several scripts that each produces some output every once in a while. I would like to be aware of the output they create, and use another script(s) to process the information they produce. Unfortunately I cannot use the multiprocessing or threading modules of Python, because the scripts can run from different machines on the same file system. I.e. each of the scripts is launched from the command line. </p>
  
  <p>All I need is that each of the queue elements is a string, and that the queue is process-safe.</p>
  
  <p>Edit: I found the modules of <a href="https://pypi.python.org/pypi/queuelib" rel="nofollow noreferrer">queuelib</a> <a href="https://pypi.python.org/pypi/pqueue/0.1.1" rel="nofollow noreferrer">pqueque</a>, but they don't provide process safety. I am thinking of maybe replacing the file handling of queuelib, with <a href="https://github.com/sashka/atomicfile" rel="nofollow noreferrer">atomicfile</a> calls. But I am afraid spending too long on debugging it, since I am short of time, and there are always fine details to care when writing software that should be process safe.</p>
  
  <p>Note1: I am using Python 2.7.</p>
  
  <p>Note2: I am aware of <a href="https://stackoverflow.com/questions/8682249/a-good-persistent-synchronous-queue-in-python">this question</a>, however my requirements are very modest, and I am looking for a simple solution, while the provided answers on that question refer to complex libraries, with no examples on how to use the queues.</p>
  
  <p>EDIT (2019): For anyone landing here, I found that <a href="https://www.sqlite.org/" rel="nofollow noreferrer">SQLite database</a> provides <a href="https://www.sqlite.org/atomiccommit.html" rel="nofollow noreferrer">atomic access</a>, it has a python API, and it is serverless. Therefore, I believe it is possible (and easy) to implement the queue in my question with it.</p>