overfl0 / Pythia

An extension for Arma 3 that lets you write extensions in Python 3
MIT License
64 stars 6 forks source link

Getting Error while iterating iterator. Report a bug!!! #67

Closed JessevGool closed 2 years ago

JessevGool commented 2 years ago

When running the following code:

async def connectToTwitch(channelName, oAuthKey, nickName):
    try:
        nickname = nickName
        token = oAuthKey
        channel = channelName
        client = Client()
        await client.login_oauth(token, nickname)
    except Exception as e:
        return str(e)

I get: image This piece of code is run in game using the following:

_channelName = twitchBot_chat_channelName; 
_oAuthKey = twitchBot_chat_oAuth; 
_nickName = twitchBot_chat_nickName;
["CCB.connectToTwitch", [_channelName, _oAuthKey, _nickName]] call py3_fnc_callExtension;

The client object comes from pytmi

overfl0 commented 2 years ago

At first glance, it looks like you're trying to use async functions in Pythia, which it doesn't support.

There is a hack where you create an async function to get data from Arma in a pseudo-asynchronous way, but that's just a Pythia hack and it has nothing to do with real python asyncio.

For now, unless some kind of asyncio support is added to Pythia itself, you would probably have to do asyncio.run ()in a separate Thread and then communicate with that thread using regular functions.

I guess the "report a bug" message comes from the fact that I didn't predict someone would actually use real asyncio in Pythia and that coroutines are iterable (so it tries to "iterate the iterator")

overfl0 commented 2 years ago

Hi! Just to let you know: I added a check that returns an error when you try to execute coroutines, because that's not supported by Pythia. This will be released along with Pythia 1.0, roughly within a month. Sadly, this does not solve your issue, just informs that what you're trying to do isn't doable out of the box.

As pointed out earlier, you could make it work, but that would require writing your own code for spinning an asyncio loop in a separate thread. See this for help: https://stackoverflow.com/questions/32059732/send-asyncio-tasks-to-loop-running-in-other-thread Be aware, though, that you'd then have to create separate functions for querying the loop to see if your data that you wanted to read is available already. You'd also have to have a function that would stop the loop when you're done with everything, at the end of the mission, for example.

I may or may not manage to add examples for doing that by the time 1.0 is released.

On another note, I have taken a look at your avatar and, funnily enough, I am able to pinpoint the exact location where that photo was taken! :D

JessevGool commented 2 years ago

Hi, I did not expect anymore responses after 6 months, I have long abandoned this project since. I'm expecting you're from the place the photo was taken, otherwise that's a very weird way to end a message

Op wo 10 aug. 2022 om 00:27 schreef Lukasz Taczuk @.***

:

Hi! Just to let you know: I added a check that returns an error when you try to execute coroutines, because that's not supported by Pythia. This will be released along with Pythia 1.0, roughly within a month. Sadly, this does not solve your issue, just informs that what you're trying to do isn't doable out of the box.

As pointed out earlier, you could make it work, but that would require writing your own code for spinning an asyncio loop in a separate thread. See this for help: https://stackoverflow.com/questions/32059732/send-asyncio-tasks-to-loop-running-in-other-thread Be aware, though, that you'd then have to create separate functions for querying the loop to see if your data that you wanted to read is available already. You'd also have to have a function that would stop the loop when you're done with everything, at the end of the mission, for example.

I may or may not manage to add examples for doing that by the time 1.0 is released.

On another note, I have taken a look at your avatar and, funnily enough, I am able to pinpoint the exact location where that photo was taken! :D

— Reply to this email directly, view it on GitHub https://github.com/overfl0/Pythia/issues/67#issuecomment-1209953925, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKCDFZ6OWYWODVICGTGHSCDVYLLNZANCNFSM5S46QPTQ . You are receiving this because you authored the thread.Message ID: @.***>

-- Met vriendelijke groet, Jesse van Gool