Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error no attr .get_running_loop in python3.6 #3941

Merged
merged 1 commit into from Oct 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions telethon/_updates/messagebox.py
Expand Up @@ -22,6 +22,7 @@
from enum import Enum
from .session import SessionState, ChannelState
from ..tl import types as tl, functions as fn
from ..helpers import get_running_loop


# Telegram sends `seq` equal to `0` when "it doesn't matter", so we use that value too.
Expand Down Expand Up @@ -53,7 +54,7 @@
_sentinel = object()

def next_updates_deadline():
return asyncio.get_running_loop().time() + NO_UPDATES_TIMEOUT
return get_running_loop().time() + NO_UPDATES_TIMEOUT


class GapError(ValueError):
Expand Down Expand Up @@ -237,7 +238,7 @@ def check_deadlines(self):
If a deadline expired, the corresponding entries will be marked as needing to get its difference.
While there are entries pending of getting their difference, this method returns the current instant.
"""
now = asyncio.get_running_loop().time()
now = get_running_loop().time()

if self.getting_diff_for:
return now
Expand Down Expand Up @@ -283,7 +284,7 @@ def reset_deadline(self, entry, deadline):

# Convenience to reset a channel's deadline, with optional timeout.
def reset_channel_deadline(self, channel_id, timeout):
self.reset_deadline(channel_id, asyncio.get_running_loop().time() + (timeout or NO_UPDATES_TIMEOUT))
self.reset_deadline(channel_id, get_running_loop().time() + (timeout or NO_UPDATES_TIMEOUT))

# Reset all the deadlines in `reset_deadlines_for` and then empty the set.
def apply_deadlines_reset(self):
Expand Down Expand Up @@ -496,7 +497,7 @@ def apply_pts_info(
# TODO store chats too?
if pts.entry not in self.possible_gaps:
self.possible_gaps[pts.entry] = PossibleGap(
deadline=asyncio.get_running_loop().time() + POSSIBLE_GAP_TIMEOUT,
deadline=get_running_loop().time() + POSSIBLE_GAP_TIMEOUT,
updates=[]
)

Expand Down
4 changes: 3 additions & 1 deletion telethon/client/updates.py
Expand Up @@ -13,6 +13,8 @@
from ..events.common import EventBuilder, EventCommon
from ..tl import types, functions
from .._updates import GapError, PrematureEndReason
from ..helpers import get_running_loop


if typing.TYPE_CHECKING:
from .telegramclient import TelegramClient
Expand Down Expand Up @@ -358,7 +360,7 @@ async def _update_loop(self: 'TelegramClient'):
continue

deadline = self._message_box.check_deadlines()
deadline_delay = deadline - asyncio.get_running_loop().time()
deadline_delay = deadline - get_running_loop().time()
if deadline_delay > 0:
# Don't bother sleeping and timing out if the delay is already 0 (pollutes the logs).
try:
Expand Down
7 changes: 7 additions & 0 deletions telethon/helpers.py
Expand Up @@ -7,6 +7,7 @@
import inspect
import logging
import functools
import sys
from pathlib import Path
from hashlib import sha1

Expand Down Expand Up @@ -423,3 +424,9 @@ def close(self, *args, **kwargs):
pass

# endregion

def get_running_loop():
if sys.version_info[:2] <= (3, 6):
return asyncio._get_running_loop()

return asyncio.get_running_loop()