-
-
Notifications
You must be signed in to change notification settings - Fork 223
RuntimeError: Event loop is closed (_ProactorBasePipeTransport.del, Windows) #315
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
Comments
I'm getting the same error with the latest master and a KL130 bulb, when running anything with asyncio
|
Can anyone check if one of these workarounds fixes the issue? Preferably the I'm not sure what's the real solution here (i.e., what should be changed in the socket handling of this lib), but if someone wants to dig and figure it out, that'd be welcome. This aiohttp issue and this python issue could provide some hints where to look at. |
I am receiving the same error in Linux (why I am stuck using 0.4.0.dev4). Device: KP303 ({'sw_ver': '1.0.10 Build 200828 Rel.162602', 'hw_ver': '1.0', 'mic_type': 'IOT.SMARTPLUGSWITCH'}) Test code (from kasa.SmartStrip examples): import asyncio
from kasa import SmartStrip
strip = SmartStrip("192.168.0.35")
asyncio.run(strip.update())
print(f"alias: {strip.alias}: {strip.hw_info}")
for plug in strip.children:
print(f"{plug.alias}: {plug.is_on}")
asyncio.run(strip.children[1].turn_on())
asyncio.run(strip.update())
print(f"is_on: {strip.is_on}") Output:
Edit: Looks like the docs are out of date. Found this comment useful |
See my previous commit if you want to help fixing this, I have no windows so I cannot really test it. |
I can testify that this stackoverflow answer solves the error message.
Code:
|
This is working for me. Although I check the platform first:
Ideally that requirement to set the event loop policy would be incorporated into python-kasa and the client application wouldn't need to know or care. So I'll leave this open for the moment, unless that's something that CAN'T be added? |
I'm open for adding that to the cli tool (if no better solution is found), but the library itself should not touch those settings as the library user may want to use a different policy for a reason or another. Feel free to open a PR if you wish, otherwise I'll see into that at some point. |
So I was about to try to find a solution to this, but I am unable to reproduce on Windows 10 using Python 3.10. Both discovery and basic commands I tested (on, off, usage, ..) on HS110 plug seem to function as expected. Tested on the master branch, and with releases 0.4.2 and 0.5.0. |
I was using Conda with Python version 3.9.12 and I was getting the same error. |
Same here (Python version 3.9.7), and this solution worked for me. Note: this didn't work for me in the base environment, only a conda virtual environment. It seems the most recent version of Anaconda won't upgrade the base environment past Python 3.9.15. |
I'm seeing this on Python 3.12, but not 3.11. My code: import asyncio
from kasa import SmartPlug
async def update_smart_plug_state(desired_state: bool):
"""Update the state of the smart plug to the desired state
Args:
desired_state (bool): The desired state of the smart plug. True for on, False for off
"""
p = SmartPlug(host="myip") # Replace with the IP of your device
# running kasa discover from the CLI gives you the IP and other details
await p.update()
print(f"Name of device: {p.alias}")
if desired_state == True:
try:
await p.turn_on()
print("Device turned on")
except Exception as e:
print(f"Error: {e}")
if desired_state == False:
try:
await p.turn_off()
print("Device turned off")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
asyncio.run(update_smart_plug_state(True)) |
There hasn't been any activity on this issue recently. This issue has been automatically marked as stale because of that. It will be closed if no further activity occurs. |
Seeing this issue on latest python-kasa and python 3.11.5 on Windows 11. Upgrading to python 3.11.11 seems to have fixed it. |
After installing and running: "kasa --target 192.168.0.255"
I get a bunch of normal output followed by:
The text was updated successfully, but these errors were encountered: