Skip to content

Commit

Permalink
Updated eventloop to use classmethod instead of staticmethod and vice…
Browse files Browse the repository at this point in the history
… versa for loophelper
  • Loading branch information
sacOO7 committed Oct 4, 2023
1 parent a385840 commit cd7fa2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions ably/executer/eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def __init__(self, loop, thread=None):
self.__thread = thread
self.__is_active = True

@staticmethod
@classmethod
def get_global(cls) -> 'AppEventLoop':
if cls._global is None or not cls._global.__is_active:
cls._global = cls.create(False)
return cls._global

@staticmethod
@classmethod
def create(cls, background=True) -> 'AppEventLoop':
loop = asyncio.new_event_loop()
thread = threading.Thread(target=loop.run_forever, daemon=background)
Expand Down
20 changes: 10 additions & 10 deletions ably/executer/eventloop_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@


class LoopHelper:
@classmethod
def run(cls, loop: events, coro, callback):
@staticmethod
def run(loop: events, coro, callback):
raise "not implemented"

@classmethod
def run_safe(cls, loop: events, coro, callback):
@staticmethod
def run_safe(loop: events, coro, callback):
raise "not implemented"

#
@classmethod
def force_sync(cls, loop: events, coro):
@staticmethod
def force_sync(loop: events, coro):
future: Future
caller_eventloop = None
try:
Expand All @@ -28,8 +28,8 @@ def force_sync(cls, loop: events, coro):
future = asyncio.run_coroutine_threadsafe(coro, loop)
return future.result()

@classmethod
def run_safe_async(cls, loop: events, coro):
@staticmethod
def run_safe_async(loop: events, coro):
caller_eventloop = None
try:
caller_eventloop: events = asyncio.get_running_loop()
Expand All @@ -45,8 +45,8 @@ def run_safe_async(cls, loop: events, coro):
# # Run in the default loop's executor
# return await loop.run_in_executor(None, blocking_fn, blocking_fn_args)

@classmethod
@staticmethod
# Run blocking function in default threadpool executor.
async def run_blocking_fn_async(cls, loop: events, blocking_fn, blocking_fn_args):
async def run_blocking_fn_async(loop: events, blocking_fn, blocking_fn_args):
# Run in the default loop's executor
return await loop.run_in_executor(None, blocking_fn, blocking_fn_args)

0 comments on commit cd7fa2b

Please sign in to comment.