1

I am a new developer and I developed a small flask app that takes excel file as input, process it and downloads the result as an excel file.

When I run in 1 browser tab the app works as expected. But if I run in multiple browser tabs simultaneously, the downloaded excel files are corrupted

I deployed the app in Beanstalk and tried running the app in two different browsers simultaneously still the excel files that are downloaded are corrupted. But if I run only 1 session it works fine.

I tried setting threaded = True but that did not help

Am I missing anything? Please help. Thanks in advance

Vkey
  • 41
  • 5
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Apr 23 '22 at 08:14

1 Answers1

0

I was able to find a work around from one of colleague. While writing to the file I hardcoded the file name like:
writer = pd.ExcelWriter("Result", engine="xlsxwriter")

What I think happened is when more than 1 session runs they try to create file with same name and write to it which cause the files corrupt.

My Solution:

import random 
key = random.randint(1, 10000) 
filename = 'Result' + str(n) + '.xlsx' 
writer = pd.ExcelWriter(file_name, engine="xlsxwriter")

This works well. You may concatenate the timestamp or add a logic to rename the file before it is downloaded.

If there is a better way to do this please comment

user11717481
  • 1
  • 9
  • 15
  • 25
Vkey
  • 41
  • 5