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

Async version of this library ? #9

Closed
Nereg opened this issue Jun 25, 2020 · 16 comments
Closed

Async version of this library ? #9

Nereg opened this issue Jun 25, 2020 · 16 comments

Comments

@Nereg
Copy link
Contributor

Nereg commented Jun 25, 2020

Hi ! I am building bot for discord using async library so I wonderd if you can create or show me async analog of this library! Also if you nedd help to re-write some code I will help !

@Yepoleb
Copy link
Owner

Yepoleb commented Jun 25, 2020

I haven't written any async code yet, but I will give it a try soon.

@Nereg
Copy link
Contributor Author

Nereg commented Jun 26, 2020

Ok ! If you nedd any help I can help you.

@InfernalPlacebo
Copy link

@Nereg what is it that you're trying to do with this that isn't working due to Async? We use this on our Discord bot just fine as is

server_info = ''
server_players = ''


async def server():
    global server_info
    global server_players
    try:
        server_info = a2s.info(server_address, 1.0)
        server_players = a2s.players(server_address)
        return True
    except:
        return False

@Yepoleb
Copy link
Owner

Yepoleb commented Jul 2, 2020

That's just marking a function as async without it actually being async. It still blocks waiting for a server response.

@Nereg
Copy link
Contributor Author

Nereg commented Jul 3, 2020

It stoped my bot for a while. I am using discord.py and may be it is their problem or it is my code. But I think I will rewrite this library.

@Nereg Nereg closed this as completed Jul 3, 2020
@Yepoleb
Copy link
Owner

Yepoleb commented Jul 3, 2020

I'll give it a try as well as soon as I have time. Let's leave this open, because this is still a feature we want to have.

@Yepoleb Yepoleb reopened this Jul 3, 2020
@iraizo
Copy link

iraizo commented Jul 9, 2020

That's just marking a function as async without it actually being async. It still blocks waiting for a server response.

Im having the same issue right now, trying to make a bot with the library, but it just blocks the code, when the server responds it just does nothing and blocks the task, is there a way you could add a timeout parameter or something?

@Yepoleb
Copy link
Owner

Yepoleb commented Jul 12, 2020

Just a quick update: I am still working on this, it's just taking me way more time than expected figuring out how to properly do async UDP. But reading docs is my top priority right now and I'm committed to delivering an async implementation soon.

@iraizo
Copy link

iraizo commented Jul 12, 2020

Just a quick update: I am still working on this, it's just taking me way more time than expected figuring out how to properly do async UDP. But reading docs is my top priority right now and I'm committed to delivering an async implementation soon.

I appreciate it

@Yepoleb
Copy link
Owner

Yepoleb commented Jul 12, 2020

Development branch: https://github.com/Yepoleb/python-a2s/tree/async

@Yepoleb
Copy link
Owner

Yepoleb commented Jul 12, 2020

Feature PR, please leave feedback if you can: #10

@Nereg
Copy link
Contributor Author

Nereg commented Jul 13, 2020

In fact I found code that asyncs some method. Here it is :

async def async_a2s_info(addr):
    loop = asyncio.get_event_loop()
    return await loop.run_in_executor(None, a2s.info, addr)

Found here

@Yepoleb
Copy link
Owner

Yepoleb commented Jul 13, 2020

Great idea to use the threading integration in asyncio to do this. The new implementation uses coroutines instead of threads though, so it scales much better, because it doesn't flood the OS with threads when mass querying.

@iraizo
Copy link

iraizo commented Jul 13, 2020

Great idea to use the threading integration in asyncio to do this. The new implementation uses coroutines instead of threads though, so it scales much better, because it doesn't flood the OS with threads when mass querying.

Running in executor and using wait for is the perfect solution, tho it’s not really async

@Nereg
Copy link
Contributor Author

Nereg commented Jul 13, 2020

Yeah if I will rewrite my code I will be better using not fast solution to async. And thanks you for all your support !

@Yepoleb
Copy link
Owner

Yepoleb commented Jul 25, 2020

Branch is now merged.

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

4 participants