diff mbox series

[v3,01/13] python/aqmp: Fix wait_closed work-around for python 3.6

Message ID 20210730201846.5147-2-niteesh.gs@gmail.com (mailing list archive)
State New, archived
Headers show
Series AQMP TUI Draft | expand

Commit Message

Niteesh G. S. July 30, 2021, 8:18 p.m. UTC
Before this patch the wait_closed work-around for python 3.6
fails during disconnect.
This is a temproray work around for which might be fixed in the
future or will be completely removed when the minimum python
version is raised to 3.7.

This patch was originally written by John Snow <jsnow@redhat.com>

Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
---
 python/qemu/aqmp/util.py | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

John Snow Aug. 5, 2021, 5:28 p.m. UTC | #1
On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu <niteesh.gs@gmail.com>
wrote:

> Before this patch the wait_closed work-around for python 3.6
> fails during disconnect.
> This is a temproray work around for which might be fixed in the
> future or will be completely removed when the minimum python
> version is raised to 3.7.
>
> This patch was originally written by John Snow <jsnow@redhat.com>
>
> Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
> ---
>  python/qemu/aqmp/util.py | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/python/qemu/aqmp/util.py b/python/qemu/aqmp/util.py
> index de0df44cbd..eaa5fc7d5f 100644
> --- a/python/qemu/aqmp/util.py
> +++ b/python/qemu/aqmp/util.py
> @@ -134,7 +134,17 @@ def is_closing(writer: asyncio.StreamWriter) -> bool:
>
>      while not transport.is_closing():
>          await asyncio.sleep(0)
> -    await flush(writer)
> +
> +    # This is an ugly workaround, but it's the best I can come up with.
> +    sock = transport.get_extra_info('socket')
> +
> +    if sock is None:
> +        # Our transport doesn't have a socket? ...
> +        # Nothing we can reasonably do.
> +        return
> +
> +    while sock.fileno() != -1:
> +        await asyncio.sleep(0)
>
>
>  def asyncio_run(coro: Coroutine[Any, Any, T], *, debug: bool = False) ->
> T:
> --
> 2.17.1
>
>
Sorry for the trouble. This is now included in the v3 version of my series
and can be dropped. I hope.
Niteesh G. S. Aug. 10, 2021, 7:54 p.m. UTC | #2
On Thu, Aug 5, 2021 at 10:58 PM John Snow <jsnow@redhat.com> wrote:

>
>
> On Fri, Jul 30, 2021 at 4:19 PM G S Niteesh Babu <niteesh.gs@gmail.com>
> wrote:
>
>> Before this patch the wait_closed work-around for python 3.6
>> fails during disconnect.
>> This is a temproray work around for which might be fixed in the
>> future or will be completely removed when the minimum python
>> version is raised to 3.7.
>>
>> This patch was originally written by John Snow <jsnow@redhat.com>
>>
>> Signed-off-by: G S Niteesh Babu <niteesh.gs@gmail.com>
>> ---
>>  python/qemu/aqmp/util.py | 12 +++++++++++-
>>  1 file changed, 11 insertions(+), 1 deletion(-)
>>
>> diff --git a/python/qemu/aqmp/util.py b/python/qemu/aqmp/util.py
>> index de0df44cbd..eaa5fc7d5f 100644
>> --- a/python/qemu/aqmp/util.py
>> +++ b/python/qemu/aqmp/util.py
>> @@ -134,7 +134,17 @@ def is_closing(writer: asyncio.StreamWriter) -> bool:
>>
>>      while not transport.is_closing():
>>          await asyncio.sleep(0)
>> -    await flush(writer)
>> +
>> +    # This is an ugly workaround, but it's the best I can come up with.
>> +    sock = transport.get_extra_info('socket')
>> +
>> +    if sock is None:
>> +        # Our transport doesn't have a socket? ...
>> +        # Nothing we can reasonably do.
>> +        return
>> +
>> +    while sock.fileno() != -1:
>> +        await asyncio.sleep(0)
>>
>>
>>  def asyncio_run(coro: Coroutine[Any, Any, T], *, debug: bool = False) ->
>> T:
>> --
>> 2.17.1
>>
>>
> Sorry for the trouble. This is now included in the v3 version of my series
> and can be dropped. I hope.
>
Thanks. I'll remove this in the upcoming v4
diff mbox series

Patch

diff --git a/python/qemu/aqmp/util.py b/python/qemu/aqmp/util.py
index de0df44cbd..eaa5fc7d5f 100644
--- a/python/qemu/aqmp/util.py
+++ b/python/qemu/aqmp/util.py
@@ -134,7 +134,17 @@  def is_closing(writer: asyncio.StreamWriter) -> bool:
 
     while not transport.is_closing():
         await asyncio.sleep(0)
-    await flush(writer)
+
+    # This is an ugly workaround, but it's the best I can come up with.
+    sock = transport.get_extra_info('socket')
+
+    if sock is None:
+        # Our transport doesn't have a socket? ...
+        # Nothing we can reasonably do.
+        return
+
+    while sock.fileno() != -1:
+        await asyncio.sleep(0)
 
 
 def asyncio_run(coro: Coroutine[Any, Any, T], *, debug: bool = False) -> T: