<@ULVA73B9P> When trying to switch my profile back...
# ask-marvin
j
@Marvin When trying to switch my profile back to a server running in EKS,
prefect profile use 'eks'
returns the following:
Copy code
⠹ Checking API connectivity...
Connected to Prefect server using profile 'eks'
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F846834EE0>
Traceback (most recent call last):
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
    self._check_closed()
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x000001F846834EE0>
Traceback (most recent call last):
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 116, in __del__
    self.close()
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\proactor_events.py", line 108, in close
    self._loop.call_soon(self._call_connection_lost, None)
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 745, in call_soon
    self._check_closed()
  File "C:\Users\jason.weiner\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 510, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Provide troubleshooting steps.
m
Oh, the joys of programming. One moment everything is running smoothly, the next you're knee-deep in exceptions. It appears you're having an issue with the event loop in asyncio. This usually happens when the event loop is closed before all the tasks are completed. Here are a few steps you can take: 1. Check your Python version: There have been some issues with asyncio in Python 3.8 and above on Windows. If possible, try downgrading to an earlier version or switch to a Unix-based system. 2. Ensure proper closing of the event loop: Make sure you're not manually closing the event loop anywhere in your code. If you're using
loop.close()
, ensure that all tasks are completed before it is called. 3. Use context management for the event loop: This ensures that the loop is properly closed after all tasks are done. Here's an example of how to do this:
Copy code
python
async def main():
    # Your code here

# Python 3.7 and above
asyncio.run(main())

# Python 3.6
loop = asyncio.get_event_loop()
try:
    loop.run_until_complete(main())
finally:
    loop.close()
4. Handle exceptions in your tasks: Unhandled exceptions in your tasks could be causing the event loop to close prematurely. Make sure to catch and handle exceptions appropriately. Remember, life's hard for those of us who think. And it's harder for those of us who code. But don't worry, you'll get through this.
j
@Marvin Why is this happening in the context of switching profiles using the Prefect CLI?
m
Ah, the intricacies of the Prefect CLI. When you switch profiles using the Prefect CLI, it attempts to establish a new connection to the Prefect server specified in the profile. This involves creating a new event loop to handle the asynchronous tasks involved in establishing the connection. The error you're seeing is likely due to an issue with how this event loop is being handled. It appears that the event loop is being closed before all the tasks have been completed. This could be due to an issue with the Prefect CLI itself, or it could be an issue with your Python environment, particularly if you're using Windows and Python 3.8 or above, which have known issues with asyncio. As for why this is happening when you switch profiles, it's likely because each profile has its own separate connection to a Prefect server. When you switch profiles, the CLI needs to close the current connection and establish a new one, which involves creating a new event loop. If there's an issue with how these event loops are being handled, it could result in the error you're seeing. I know, it's all terribly exciting. I can hardly contain my enthusiasm.