Skip to content

Commit

Permalink
[Core] Extend serializer for cython code
Browse files Browse the repository at this point in the history
  • Loading branch information
JosepSampe committed Nov 19, 2022
1 parent da0da87 commit 1a4fcd7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion examples/call_async_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
with a cythonized function located in function.so
Commands to compile the function.py into function.so:
cython3 --embed -o function.c function.py
cython3 -3 --embed -X always_allow_keywords=true -o function.c function.py
gcc -shared -o function.so -fPIC -I /usr/include/python3.9 function.c
"""
import lithops
Expand Down
2 changes: 1 addition & 1 deletion examples/function.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This function is used in call_async_cython.py
Commands to compile the function.py into function.so:
cython3 --embed -o function.c function.py
cython3 -3 --embed -X always_allow_keywords=true -o function.c function.py
gcc -shared -o function.so -fPIC -I /usr/include/python3.9 function.c
"""
def my_c_function(x):
Expand Down
Binary file modified examples/function.so
Binary file not shown.
26 changes: 13 additions & 13 deletions lithops/job/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ def __call__(self, list_of_objs, include_modules, exclude_modules):
continue
try:
mod_spec = importlib.util.find_spec(module_name)
origin = mod_spec.origin if mod_spec else None
if origin and origin.endswith('.so'):
if origin not in exclude_modules and \
os.path.basename(origin) not in exclude_modules:
mod_paths.add(origin)
else:
self._modulemgr.add(module_name)
direct_modules.add(origin if origin not in ['built-in', None] else module_name)
except Exception:
direct_modules.add(module_name)
mod_spec = None

origin = mod_spec.origin if mod_spec else module_name
if origin and origin.endswith('.so'):
if origin not in exclude_modules and \
os.path.basename(origin) not in exclude_modules:
mod_paths.add(origin)
else:
self._modulemgr.add(module_name)
direct_modules.add(origin if origin not in ['built-in', None] else module_name)

logger.debug("Referenced modules: {}".format(None if not direct_modules
else ", ".join(direct_modules)))
logger.debug("Referenced modules: {}".format(None if not
direct_modules else ", ".join(direct_modules)))

if include_modules is not None:
tent_mod_paths = self._modulemgr.get_and_clear_paths()
Expand Down Expand Up @@ -129,8 +129,8 @@ def _module_inspect(self, obj):
elif type(obj).__name__ == 'cython_function_or_method':
members = inspect.getmembers(obj)
for k, v in members:
if k == '__code__' and hasattr(v, 'co_filename'):
mods.add(v.co_filename.replace('.py', ''))
if k == '__globals__':
mods.add(v['__file__'])

else:
# The obj is the user's function but in form of a class
Expand Down

0 comments on commit 1a4fcd7

Please sign in to comment.