Repository: doronz88/pymobiledevice3 (language: python)

Issue:
Another: There is no current event loop   loop = asyncio.get_event_loop()
PY 3.12
Win 10
iPhone 17.4.1.

Launching an app on iOS 17.4.1 - the app launches on the iPhone but the launching process gets a message about "no current event loop" and exits.

**To Reproduce**
Steps to reproduce the behavior:
1. python3.exe -m pymobiledevice3 developer dvt launch {appBundleId} --tunnel {iosDeviceUDID}  --no-color
Message: 
C:\Users\jjensen\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.12_qbz5n2kfra8p0\LocalCache\local-packages\Python312\site-packages\pymobiledevice3\utils.py:55: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
Process launched with pid 609

Process exited!

The DiskImage is already mounted before the tunneld process starts. That's from the other reference to this issue.
Normally I would assume the process would not get this message and not exit. All the other commands seem to work fine, so not sure
what the issue is. Appreciate any help.


**Additional context**
This occurs on both iOS17.4.1 phones that I have.

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**


Discussion / hints:
Additional note: added --stream to the command line and the process is not exiting, still get the "no current event loop" in the output but getting data out of the app now.

Fix patch:
diff --git a/pymobiledevice3/utils.py b/pymobiledevice3/utils.py
index 6b514ddea..625ebdad1 100644
--- a/pymobiledevice3/utils.py
+++ b/pymobiledevice3/utils.py
@@ -52,7 +52,7 @@ async def wrapper(*args, **kwargs):
 
 def get_asyncio_loop() -> asyncio.AbstractEventLoop:
     try:
-        loop = asyncio.get_event_loop()
+        loop = asyncio.get_running_loop()
         if loop.is_closed():
             raise RuntimeError('The existing loop is closed.')
     except RuntimeError:


Test patch:
diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py
index 81b614ed7..06ba3e441 100644
--- a/tests/cli/test_cli.py
+++ b/tests/cli/test_cli.py
@@ -1,5 +1,5 @@
-import shlex
 import subprocess
+import sys
 
 import pytest
 from click.testing import CliRunner
@@ -27,5 +27,4 @@ def test_cli_groups(group):
 
 @pytest.mark.parametrize('group', __main__.CLI_GROUPS.keys())
 def test_cli_from_python_m_flag(group):
-    cmd = shlex.split(f'python -m pymobiledevice3 {group} --help')
-    subprocess.run(cmd, check=True)
+    subprocess.run([sys.executable, '-m', 'pymobiledevice3', group, '--help'], check=True)