Skip to content

Using an OCaml library from multithreaded Python code #76

@jonathan-laurent

Description

@jonathan-laurent

Thanks for developing and maintaining this great package!

I am currently using pyml and pythonlib to call an OCaml library from Python. My Python application is using multiple threads (using concurrent.futures.ThreadPool), although these threads never run in parallel (thanks to the GIL).

So far, things have been working fine for me. However, I found this in the OCaml documentation:
https://ocaml.org/manual/intfc.html#ss:c-thread-register

Callbacks from C to OCaml are possible only if the calling thread is known to the OCaml run-time system. Threads created from OCaml (through the Thread.create function of the system threads library) are automatically known to the run-time system. If the application creates additional threads from C and wishes to callback into OCaml code from these threads, it must first register them with the run-time system. The following functions are declared in the include file <caml/threads.h>.: [caml_c_thread_register() and caml_c_thread_unregister()].

Does pyml need to do anything special to deal with these? My application seems to be doing fine right now but I am worried about subtle bugs or leaks in the future.

@LaurentMazare Do you have any experience calling ocaml libraries from multithreaded python code at Janestreet?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions