I’m facing a challenge with my Streamlit application, particularly when handling concurrent user sessions. My application is designed to administer a personality test, and the results are sent to users via email. However, I’ve encountered an issue where, if multiple users (e.g., Person A and Person B) are using the app simultaneously, there’s a mix-up in the session management. As a result, Person A might receive Person B’s results, and vice versa.
Details:
Error Description: No specific error message, but incorrect session handling leading to mixed-up email results.
Attempts to Resolve: I’ve looked into session management in Streamlit but haven’t found a specific method to implement a queue system for handling multiple users. I’m unsure how to segregate individual user sessions effectively.
Streamlit Version: 1.26.0
Python Version: 3.9 (Anaconda)
Operating System: Tested on Windows 10, Windows 11 and MacOS Monterey
I’m looking for guidance or suggestions on how to ensure that each user session is handled independently, especially in a way that the email feature sends the correct results to each user. Any advice on implementing a queue or better session management in Streamlit would be greatly appreciated.
Session State is isolated for each user so there is nothing to do to segregate them. If you are getting some kind of mix, my first suspect would be caching or maybe a mishandled connection. (If a function is cached, then the saved output can be returned for other users.)
Can you be more specific about what mix you are observing?
How are you saving and handling this document? Do you write anything to disk with non-unique filenames that might be read in another session? (I don’t quite have time to dig through your repo just now, so if you could point me to the right spot that would help.)
I am not sure if you point that, but I also have a Google Drive API for save word docs to Google Drive. I just disabled it, and it works perfectly! I just tried with two users at the same time and will try four users.
I think the problem is about Google Drive API connection, also looked at console and saw this;
Traceback (most recent call last):
File "/home/adminuser/venv/lib/python3.9/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 541, in _run_script
exec(code, module.__dict__)
File "/mount/src/kyyk-renkler-kisilik/main.py", line 24, in <module>
kontrol_butonu()
File "/mount/src/kyyk-renkler-kisilik/utils.py", line 885, in kontrol_butonu
send_mail.send_analysis(mail, [dosya_adi])
File "/mount/src/kyyk-renkler-kisilik/send_mail.py", line 73, in send_analysis
server.sendmail(FROM, TO, text)
File "/usr/local/lib/python3.9/smtplib.py", line 901, in sendmail
raise SMTPRecipientsRefused(senderrs)
smtplib.SMTPRecipientsRefused: {'': (555, b'5.5.2 Syntax error. Please visit\n5.5.2 https://support.google.com/a/answer/3221692 and review RFC 5321\n5.5.2 specifications for more information. g12-20020a170902c38c00b001bbd1562e75sm1509755plg.55 - gsmtp')}
2023-10-20 17:07:26.002 Session with id 2af1d343-5075-4515-9902-49aeb28f4630 is already connected! Connecting to a new session.
It looks like an error about sending mail, but disabling Google Drive part is works fine right now!
Module-level variables (like mail in utils.py) are shared across sessions. So each time mail is assigned a value, it will be seen by all sessions. You probably want to store such values in session_state.
Thanks for your reply! I think I really need a session-based approach. I will try to reconstruct my app and also try it with Google Drive API. Thanks for your all suggestions!
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.