Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8153213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:56:38+00:00 2026-06-06T15:56:38+00:00

Is openpyxl thread safe? I’m hoping to have one thread changing the worksheet while

  • 0

Is openpyxl thread safe?
I’m hoping to have one thread changing the worksheet while another thread saves at regular intervals. I was wondering if I needed to add a lock object around the changing and saving operations or whether that is already built in to openpyxl. I did not see anything in the documentation nor any previous questions about threads in openpyxl.

After reading your answer I ran the following test:

import threading 
import random 
import time 
from openpyxl import Workbook

wb = Workbook() 

class openpyxlwriting ( threading.Thread): 

    def run ( self ): 

        global wb
        ws = wb.get_active_sheet()
        c = 1 
        for a in range(100):
            for b in range(10000):
                ws.cell(column = a,row=b).value = c
                c += 1
            print "row ",a

class openpyxlsaving ( threading.Thread): 

    def run ( self ): 

        global wb

        for a in range(1000): 
            wb.save('test.xlsx')
            print "saved"

openpyxlwriting().start()
time.sleep(1)
openpyxlsaving ().start()

which gave me the following trasback:
trasback.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:56:41+00:00Added an answer on June 6, 2026 at 3:56 pm

    I decided to see if I could test this, so I created the simple program below that generates a bunch of threads that attempt to read and write the same cell, with random sleeps thrown in.

    I didn’t see any OS errors that might indicate a problem. On the other hand, I did see some behavior that I didn’t quite understand. As the thread count increased, the number of loops completed decreased. So, for example, thread 100 only completed 8 passes through the loop. This might be some sort of an error on my part, or it might indicate an issue with thread safety.

    Anyway, this should give you a start in testing it yourself, if you feel so inclined.

    import threading
    import random
    import time
    from openpyxl import Workbook
    
    wb = Workbook()
    ws = wb.get_active_sheet()
    testcell = ws.cell('B9')
    counter = 1
    
    class openpyxlworker ( threading.Thread):
    
        def run ( self ):
    
            global wb     
            global testcell
            global counter
    
            for a in range(1000):
                time.sleep(random.random()/100)
                writing = random.randrange(1, 1000)
                testcell.value = writing
                time.sleep(random.random()/100)
                reading = testcell.value          
                print "Thread " + str(counter) + " wrote " + str(writing) + " and read " + str(reading)
                time.sleep(random.random()/100)
                wb.save('test.xlsx')
    
            counter = counter + 1
    
    for b in range(100):
        openpyxlworker().start()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed openpyxl in ubuntu. now I am running the openpyxl with xlsx
I have a spreadsheet of data I am parsing using openpyxl's iter_rows function. However
I use easy_install to install the openpyxl and it was successfully installed. However when
I am working on .xlsx using python & I am using openpyxl for the
Using the python library openpyxl I am reading an XLSX file created in excel
I plan to use one of 2 libraries below to output excel file in
I need advice on setting styles in Openpyxl. I see that the NumberFormat of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.