multiple connections to same spreadsheet (gspread)
<p>Good Morning, this is my first question so please bear with me! I created a system for doing a mock election at my high school that uses a raspberry pi and a touchscreen. The interface is handled through TKInter and the results are then appended to a google sheet using gspread. This allows me to then process the data in a variety of charts and analysis. </p>

<p>The issue I'm running into is that I am using 4 machines. If I take them one at a time they append the data fine. If I do multiple machines at once I SOMETIMES get one just waiting for the other and sometimes only 1 of the 4 is recorded. </p>

<p>Is there a may to better set things up to push multiple appends simultaneously from the different machines? Currently each machine is a mirror of the others. Would it work better if I did a different authorization setup and different JSON file for each machine? Or is there something else that I am missing? The relavaent code to writing to the sheet is below:</p>

<pre><code>    #while True:
    # Login if necessary.
    if worksheet is None:
        worksheet = login_open_sheet(GDOCS_OAUTH_JSON, GDOCS_SPREADSHEET_NAME)

    # Append the data in the spreadsheet, including a timestamp
    try:
        worksheet.append_row((datetime.datetime.now(), gender, grade, party, vote))
    except:
        # Error appending data, most likely because credentials are stale.
        # Null out the worksheet so a login is performed at the top of the loop.
        print('Append error, logging in again')
        worksheet = None
</code></pre>

<p>Thank you in advance for your assistance!!</p>

<p>The issue here is that if you have all four of these machines starting at the same time they will have a relatively similar state for the sheet. However, once a single machine has made a change the state for all the others becomes different from the actual sheet.</p>

<p>Lets say the sheet starts with N rows.</p>

<p>If Machine1 appends 2 rows to the sheet the number of rows then becomes the N + 2.</p>

<p>BUT</p>

<p>Machines 2-4 still think the sheet has N rows!</p>

<p>When any of these N-row machines tries to append to the sheet they will overwrite the data that Machine1 wrote to the sheet, obviously not something you want to happen when you're tallying votes.</p>

<p>You'll either need to find a way to let each machine know when the state of the sheet has changed and refresh its state or have a single point of contact from which all the appends are made.</p>

python gspread