Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract data from run_forever() into a variable #598

Closed
kyungingh opened this issue Jan 24, 2020 · 2 comments
Closed

Extract data from run_forever() into a variable #598

kyungingh opened this issue Jan 24, 2020 · 2 comments

Comments

@kyungingh
Copy link

When running run_forever() in the class WebSocketApp, the data from server is usually displayed (log). Is there any way to save (dump) this data into a variable inside the script?

@M00NSH0T
Copy link

M00NSH0T commented Feb 14, 2020

I've been doing something like what you're talking about involving dataframes. In my case, I'm creating a custom class and saving what I need to a class variable from within the class's "on_message" method, which is what my class's websocketapp calls when a message comes in. Alternatively, the functional approach would be to use a global that you can use elsewhere, like below.

messages=[]    

def on_message(ws, message):
        global messages
        messages.append(message) #or whatever else you want to do.

I should point out that I have been struggling with issues as I scale things up. When I'm just receiving a few dozen messages per minute, there's no issue, but once I start receiving thousands, the delays that some of my calculations cause seem to be filling up a buffer somewhere (at least that's my theory at the moment). All of a sudden, I stop receiving messages, and don't get any error message to help sort things out. Again, this works at a small scale, so might be worth a shot for you.

I'm sure there's a way to handle all this with asyncio or maybe threading, but I'm still struggling with that part of it.

@engn33r
Copy link
Collaborator

engn33r commented Mar 29, 2021

I think the answer from @M00NSH0T is a good approach. If you are looking at asyncio, issue #496 indicates that this library probably is not compatible, but I have not tested it myself. If you specifically want to handling log messages (which includes warnings, etc.) you can try using Sentry, which was referenced in issue #639.

@engn33r engn33r closed this as completed Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants