Skip to content

Commit

Permalink
[shortfin] Fix some issues blocking operation on Python 3.10. (#462)
Browse files Browse the repository at this point in the history
With this unit tests appear to pass (I'm on a system with other issues
but appear unrelated).
  • Loading branch information
stellaraccident authored Nov 9, 2024
1 parent 86ff97d commit 2cbf768
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 18 additions & 2 deletions shortfin/python/_shortfin/asyncio_bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

import asyncio
import inspect

from . import lib as sfl


# Feature detect some versions where signatures changes.
if "context" in inspect.signature(asyncio.Task).parameters:
# Python > 3.10
_ASYNCIO_TASK_HAS_CONTEXT = True
else:
_ASYNCIO_TASK_HAS_CONTEXT = False


class PyWorkerEventLoop(asyncio.AbstractEventLoop):
def __init__(self, worker: sfl.local.Worker):
self._worker = worker
Expand All @@ -17,8 +26,15 @@ def get_debug(self):
# Requirement of asyncio.
return False

def create_task(self, coro, *, name=None, context=None):
return asyncio.Task(coro, loop=self, name=name, context=context)
if _ASYNCIO_TASK_HAS_CONTEXT:

def create_task(self, coro, *, name=None, context=None):
return asyncio.Task(coro, loop=self, name=name, context=context)

else:

def create_task(self, coro, *, name=None):
return asyncio.Task(coro, loop=self, name=name)

def create_future(self):
return asyncio.Future(loop=self)
Expand Down
2 changes: 1 addition & 1 deletion shortfin/python/shortfin_apps/sd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def get_modules(args):
f"--model={modelname}",
f"--iree-hal-target-device={args.device}",
f"--iree-hip-target={args.target}",
f"--iree-compile-extra-args={" ".join(ireec_args)}",
f"--iree-compile-extra-args={' '.join(ireec_args)}",
]
print("BUILDER INPUT:\n", " \ \n ".join(builder_args))
output = subprocess.check_output(builder_args).decode()
Expand Down

0 comments on commit 2cbf768

Please sign in to comment.