|
@@ -163,6 +163,12 @@ class WFStreamWriter: |
|
|
|
|
|
|
|
|
return self._closed |
|
|
return self._closed |
|
|
|
|
|
|
|
|
|
|
|
async def _close_task(self): |
|
|
|
|
|
await self._client._sendcmd(dict(cmd='chanclose', chan=self._stream)) |
|
|
|
|
|
|
|
|
|
|
|
self._closed_event.set() |
|
|
|
|
|
self._closed_event = None |
|
|
|
|
|
|
|
|
def close(self): |
|
|
def close(self): |
|
|
''' |
|
|
''' |
|
|
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.close |
|
|
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.close |
|
@@ -170,20 +176,18 @@ class WFStreamWriter: |
|
|
|
|
|
|
|
|
self._closed = True |
|
|
self._closed = True |
|
|
|
|
|
|
|
|
self._closed_event.set() |
|
|
|
|
|
self._closed_event = None |
|
|
|
|
|
|
|
|
|
|
|
self._closetask = asyncio.create_task(self._client._sendcmd(dict(cmd='chanclose', chan=self._stream))) |
|
|
|
|
|
|
|
|
self._closetask = asyncio.create_task(self._close_task()) |
|
|
|
|
|
|
|
|
async def wait_closed(self): |
|
|
async def wait_closed(self): |
|
|
''' |
|
|
''' |
|
|
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.wait_closed |
|
|
https://docs.python.org/3/library/asyncio-stream.html#asyncio.StreamWriter.wait_closed |
|
|
''' |
|
|
''' |
|
|
|
|
|
|
|
|
if self._closed: |
|
|
|
|
|
|
|
|
ce = self._closed_event |
|
|
|
|
|
if ce is None: |
|
|
return |
|
|
return |
|
|
|
|
|
|
|
|
await self._closed_event.wait() |
|
|
|
|
|
|
|
|
await ce.wait() |
|
|
|
|
|
|
|
|
class WSFWDCommon: |
|
|
class WSFWDCommon: |
|
|
''' |
|
|
''' |
|
@@ -683,6 +687,9 @@ class Test(unittest.IsolatedAsyncioTestCase): |
|
|
stdin.close() |
|
|
stdin.close() |
|
|
await stdin.wait_closed() |
|
|
await stdin.wait_closed() |
|
|
|
|
|
|
|
|
|
|
|
# that it can be awaited multiple times |
|
|
|
|
|
await stdin.wait_closed() |
|
|
|
|
|
|
|
|
self.assertEqual(await stdout.read(), b'') |
|
|
self.assertEqual(await stdout.read(), b'') |
|
|
|
|
|
|
|
|
self.assertEqual(await proc.wait(), 0) |
|
|
self.assertEqual(await proc.wait(), 0) |