From 47572774e40cd57e00fadef208d19f0418c25090 Mon Sep 17 00:00:00 2001 From: Guillaume Bouchard Date: Mon, 24 Aug 2026 18:11:39 +0400 Subject: [PATCH 1/2] doc: document troubleshooting - ghci loading workaround, see #43. - ghci reloading behavior, see #44. - async exception and uninterruptible calls, see #48. --- src/Python/Inline.hs | 51 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/src/Python/Inline.hs b/src/Python/Inline.hs index d387930..8b5a8e5 100644 --- a/src/Python/Inline.hs +++ b/src/Python/Inline.hs @@ -133,5 +133,52 @@ import Python.Internal.Eval -- -- Attempting to import library using C extensions from ghci may -- result in linker failing to find symbols from @libpython@ like --- @PyFloat_Type@ or some other. Only known workaround is to set --- @LD_PRELOAD=/path/to/libpython3.XX.so@ environment variable. +-- @PyFloat_Type@ or some other. There are multiples known workarounds: +-- +-- +-- - export @LD_PRELOAD=/path/to/libpython3.XX.so@ environment variable. This +-- works fine most of the time but it will also impact programs called from +-- your repl (e.g. using 'process'). +-- - you can load the relevant symbol only in the current process space using +-- +-- > System.Posix.DynamicLinker.dlopen "/path/to/lib/libpython3.XX.so" [System.Posix.DynamicLinker.RTLD_NOW, System.Posix.DynamicLinker.RTLD_GLOBAL] +-- +-- Note that in ghci, you don't need to explicitly import +-- "System.Posix.DynamicLinker" to run this command. If you use this +-- extensively in your project, it is recommended to add that in your @.ghci@, +-- either as an unconditionally executed command, or as a macro, such as: +-- +-- > :def setupPythonDLL \_ -> "" <$ System.Posix.DynamicLinker.dlopen "path/to//lib/libpython3.so" [System.Posix.DynamicLinker.RTLD_NOW, System.Posix.DynamicLinker.RTLD_GLOBAL]@ +-- +-- 4. __GHCi reload__ +-- +-- Even if you reload ghci (using @:reload@), the python environment stays +-- initialised. As a result, the python modules imported using 'Python.Inline.QQ.pymain' won't +-- be reloaded, which is often source of confusion. +-- +-- You can use python's @importlib.reload(m)@. For example: +-- +-- > +-- > [pymain| +-- > import json +-- > import importlib +-- > import pandas +-- > import mylib +-- > +-- > # This force reloads mylib +-- > importlib.reload(run_saem) +-- > |] +-- +-- +-- Note that there is a performance drawback, the side effects of 'import' are +-- redone and python does not give much guarantee about what is happening here. +-- Use it with caution. We recommend using @importlib.reload@ only during +-- development and not in production. +-- +-- 5. __Asynchronous exceptions__ +-- +-- The code run by 'runPy' is not interruptible by Haskell asynchronous +-- exceptions and may block indefinitely. If your code call any Haskell +-- function as callback, they won't receive asynchronous exception either. See +-- https://github.com/Shimuuar/inline-python/issues/48 for details and +-- workarounds. From ae1a869c4960bad9d6db1093b5bc0323ef5d4c45 Mon Sep 17 00:00:00 2001 From: Alexey Khudyakov Date: Wed, 2 Sep 2026 12:31:35 +0300 Subject: [PATCH 2/2] Lightly edit documentation --- src/Python/Inline.hs | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Python/Inline.hs b/src/Python/Inline.hs index 8b5a8e5..c837ceb 100644 --- a/src/Python/Inline.hs +++ b/src/Python/Inline.hs @@ -132,21 +132,24 @@ import Python.Internal.Eval -- 3. __Linker error in GHCi__ -- -- Attempting to import library using C extensions from ghci may --- result in linker failing to find symbols from @libpython@ like --- @PyFloat_Type@ or some other. There are multiples known workarounds: +-- result in linker failing to find symbols from @libpython3@ like +-- @PyFloat_Type@ or some other. There are multiples known +-- workarounds. @libpython3.XX.so@ should be one @inline-python@ was +-- built with. -- --- --- - export @LD_PRELOAD=/path/to/libpython3.XX.so@ environment variable. This +-- - export @LD_PRELOAD=\/path\/to\/libpython3.XX.so@ environment variable. This -- works fine most of the time but it will also impact programs called from -- your repl (e.g. using 'process'). +-- -- - you can load the relevant symbol only in the current process space using -- --- > System.Posix.DynamicLinker.dlopen "/path/to/lib/libpython3.XX.so" [System.Posix.DynamicLinker.RTLD_NOW, System.Posix.DynamicLinker.RTLD_GLOBAL] +-- > System.Posix.DynamicLinker.dlopen "/path/to/libpython3.XX.so" [System.Posix.DynamicLinker.RTLD_NOW, System.Posix.DynamicLinker.RTLD_GLOBAL] -- -- Note that in ghci, you don't need to explicitly import -- "System.Posix.DynamicLinker" to run this command. If you use this --- extensively in your project, it is recommended to add that in your @.ghci@, --- either as an unconditionally executed command, or as a macro, such as: +-- extensively in your project, it is recommended to add that in your +-- @.ghci@, global or local, either as an unconditionally executed +-- command, or as a macro, such as: -- -- > :def setupPythonDLL \_ -> "" <$ System.Posix.DynamicLinker.dlopen "path/to//lib/libpython3.so" [System.Posix.DynamicLinker.RTLD_NOW, System.Posix.DynamicLinker.RTLD_GLOBAL]@ -- @@ -166,7 +169,7 @@ import Python.Internal.Eval -- > import mylib -- > -- > # This force reloads mylib --- > importlib.reload(run_saem) +-- > importlib.reload(mylib) -- > |] -- --