Use ensure_future instead of create_task in AsyncStream
authorHarmon <Harmon758@gmail.com>
Wed, 19 May 2021 12:05:08 +0000 (07:05 -0500)
committerHarmon <Harmon758@gmail.com>
Wed, 19 May 2021 12:05:08 +0000 (07:05 -0500)
Maintain support for Python 3.6

tweepy/asynchronous/streaming.py

index 1c7a559036b5a9caf8b5b834bef81e1d27c06fd3..3a6b5a32dade0b148e309964e7f2f006a54b9d19 100644 (file)
@@ -227,9 +227,10 @@ class AsyncStream:
         if stall_warnings:
             body["stall_warnings"] = "true"
 
-        self.task = asyncio.create_task(
+        self.task = asyncio.ensure_future(
             self._connect("POST", endpoint, headers=headers, body=body or None)
         )
+        # Use create_task when support for Python 3.6 is dropped
         return self.task
 
     def sample(self, *, languages=None, stall_warnings=False):
@@ -277,9 +278,10 @@ class AsyncStream:
         if stall_warnings:
             params["stall_warnings"] = "true"
 
-        self.task = asyncio.create_task(
+        self.task = asyncio.ensure_future(
             self._connect("GET", endpoint, params=params)
         )
+        # Use create_task when support for Python 3.6 is dropped
         return self.task
 
     def disconnect(self):