Skip to content

Commit 10a4c4f

Browse files
author
Hoyt Koepke
committed
Merge branch 'pylambda-cythonization-and-a-hypernewt' of github.com:hoytak/SFrame into pylambda-cythonization-and-a-hypernewt
2 parents ad408db + 70220c2 commit 10a4c4f

3 files changed

Lines changed: 29 additions & 11 deletions

File tree

oss_src/unity/python/sframe/_scripts/CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ set_source_files_properties("pyspark_unity.pyx" PROPERTIES CYTHON_IS_CXX TRUE)
44
set_source_files_properties("../cython/cy_flexible_type.pyx" PROPERTIES CYTHON_IS_CXX TRUE)
55
set_source_files_properties("../cython/cy_callback.pyx" PROPERTIES CYTHON_IS_CXX TRUE)
66

7+
# This is annoying
8+
get_directory_property( cur_include_directories INCLUDE_DIRECTORIES )
9+
list( APPEND cur_include_directories "${CMAKE_CURRENT_SOURCE_DIR}/../cython")
10+
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "${cur_include_directories}")
11+
712
# To avoid complicated library dependencies on these modules, we need
813
# to include additional cython files as part of this executable.
9-
cython_add_standalone_executable(pyspark_unity
10-
MAIN_MODULE "pyspark_unity.pyx"
11-
"../cython/cy_flexible_type.pyx"
12-
"../cython/cy_callback.pyx")
1314

14-
set_property(TARGET pyspark_unity APPEND_STRING PROPERTY LINK_FLAGS " -Wl,-rpath,$ORIGIN -Wl,-rpath,$ORIGIN/.. -Wl,-rpath,${CMAKE_CURRENT_BINARY_DIR} ")
15+
cython_add_standalone_executable(pyspark_unity MAIN_MODULE
16+
"pyspark_unity.pyx" "../cython/cy_flexible_type.pyx"
17+
"../cython/cy_callback.pyx")
18+
19+
set_property(TARGET pyspark_unity
20+
APPEND_STRING PROPERTY
21+
LINK_FLAGS " -Wl,-rpath,$ORIGIN -Wl,-rpath,$ORIGIN/.. -Wl,-rpath,${CMAKE_CURRENT_BINARY_DIR} ")
22+
1523
target_link_libraries(pyspark_unity python_callbacks spark_unity unity_core)
1624
add_dependencies(pyspark_unity release_binaries)
1725

oss_src/unity/python/sframe/_scripts/pyspark_unity.pyx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# in the CMakeLists pulls in the cython source files directly, so we
44
# don't actually depend on these libraries at link time.
55

6-
from ..cython.cy_flexible_type cimport flexible_type, flex_type_enum, UNDEFINED
7-
from ..cython.cy_flexible_type cimport flexible_type_from_pyobject
8-
from ..cython.cy_flexible_type cimport pyobject_from_flexible_type
9-
from ..cython.cy_callback cimport register_exception
6+
from cy_flexible_type cimport flexible_type, flex_type_enum, UNDEFINED
7+
from cy_flexible_type cimport flexible_type_from_pyobject
8+
from cy_flexible_type cimport pyobject_from_flexible_type
9+
from cy_callback cimport register_exception
1010

1111
from libcpp.string cimport string
1212
from libcpp.vector cimport vector
@@ -29,6 +29,10 @@ cdef extern from "<sframe/sframe.hpp>" namespace "graphlab":
2929
string column_name(size_t idx)
3030
size_t num_columns()
3131

32+
cdef extern from "<cstdlib>":
33+
void _exit(int)
34+
35+
3236
cdef extern from "<sframe/sframe_iterators.hpp>" namespace "graphlab":
3337

3438
cdef cppclass parallel_sframe_iterator_initializer:
@@ -106,7 +110,12 @@ cdef call_main():
106110
for i in range(len(args)):
107111
c_args[i] = args[i]
108112

109-
sys.exit(_spark_unity_main(len(args), c_args.data()))
113+
# If this script is run with a different libpython minor version,
114+
# e.g. 2.7.6 vs 2.7.10, or 2.7.11 vs 2.7.10, there appears to be
115+
# race condition in tearing things down. Everything appears to
116+
# work besides that. Using sys._exit instead of exit gets around
117+
# this.
118+
_exit(_spark_unity_main(len(args), c_args.data()))
110119

111120

112121
if __name__ == "__main__":

oss_src/unity/python/sframe/cython/cy_flexible_type.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ try:
236236
from ..data_structures import image
237237
_image_type = image.Image
238238
have_imagetype = True
239-
except ImportError:
239+
except Exception: # relative import can raise ValueError or
240+
#ImportError, so catch anything
240241
have_imagetype = False
241242
_image_type = __bad_image
242243

0 commit comments

Comments
 (0)