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

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

Closed
JessevGool opened this issue Apr 8, 2022 · 3 comments
Closed

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

JessevGool opened this issue Apr 8, 2022 · 3 comments
Milestone

Comments

@JessevGool
Copy link

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
Copy link
Owner

overfl0 commented Apr 8, 2022

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 overfl0 added this to the 1.0 milestone Aug 6, 2022
@overfl0 overfl0 closed this as completed in 4807ec3 Aug 9, 2022
@overfl0
Copy link
Owner

overfl0 commented Aug 9, 2022

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
Copy link
Author

JessevGool commented Aug 10, 2022 via email

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

2 participants