question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to dynamically get current user list by using session?

See original GitHub issue

Hi Miguel, I’m a junior developer, I’m sorry to make you spend some time on this question…

  • I’m using Flask-SocketIO to try to build a chat server without using any database or user list stored in the back-end.
  • I just simply store the username into session and authenticate the username info by Flask-Login, so that I can use SocketIO to get the current_user.

So here is the question:

How could I get the current user list by dynamically retrieving the sessions from different users, in order to let every user who has logged in see the list?

Thank you for reading this, I would appreciate it if you could give me some handy tips 😃😃😃

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
miguelgrinbergcommented, Dec 6, 2016

Example:

@socketio.on('connect')
def user_connect():
    session['thread'] = socketio.start_background_task(background_thread, session['user'])

This sends the user as an argument to your thread function (you’ll have to add the argument on your thread function, obviously). It also stores the thread in the user session, so that you can then access it when you need to stop it.

1reaction
shisaqcommented, Dec 6, 2016

It works! Thank you for your help! I feel extremely excited now! It’s really a nice idea to store the thread into the session, I never thought about it before! @miguelgrinberg

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Dynamic PowerShell to Get Current Users
Learn how use PowerShell to get current users in this step-by-step tutorial walking you through how to do so many different ways!
Read more >
How to dynamically display user name from the database after ...
<?php $user = User::find_by_id($_SESSION['user_id']); ?> Note: To make your templating cleaner, you can use the shorthand syntax for echo :
Read more >
Get the currently logged in user id (generating dynamic url ...
I want to add a property based on currently logged in user id or just help me to access the currently logged-in user...
Read more >
Solved: Get executing user in Flow - Power Platform Community
Solved: I need to send email to the user who executed the flow on a selected item in document library. I am using...
Read more >
How to display logged in user information in PHP
Explanation: The session is started using session_start() method. After that, the variables are declared and an error array is created. It will ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found