Skip to content

Add erlang.whereis() for Python to lookup registered Erlang PIDs#39

Merged
benoitc merged 1 commit intomainfrom
feature/whereis-lookup
Mar 18, 2026
Merged

Add erlang.whereis() for Python to lookup registered Erlang PIDs#39
benoitc merged 1 commit intomainfrom
feature/whereis-lookup

Conversation

@benoitc
Copy link
Owner

@benoitc benoitc commented Mar 18, 2026

Summary

  • Add erlang.whereis() Python function to lookup registered Erlang processes
  • Accepts str, bytes, or erlang.Atom as the name argument
  • Returns erlang.Pid if found, None if not registered
  • Uses Erlang callback mechanism for reliable cross-thread operation

Usage

import erlang

pid = erlang.whereis("my_server")
if pid is not None:
    erlang.send(pid, {"request": "data"})

Implement whereis lookup that allows Python code to find Erlang processes
registered with erlang:register/2.

Implementation:
- Add erlang.whereis() Python function that accepts str, bytes, or Atom
- Use Erlang callback mechanism (_whereis) instead of direct enif_whereis_pid
  to avoid crashes with certain OTP configurations
- Register _whereis callback in py_callback:register_callbacks/0 at startup

Usage:
  pid = erlang.whereis("my_server")  # Returns Pid or None
  pid = erlang.whereis(erlang.atom("my_server"))  # Also works with atoms

Tests:
- test_whereis_registered_process: lookup existing registered process
- test_whereis_nonexistent: lookup non-registered name returns None
- test_whereis_with_atom: lookup using erlang.Atom type
- test_whereis_with_bytes: lookup using bytes
- test_whereis_invalid_type: invalid argument raises TypeError
@benoitc benoitc merged commit 4b44e53 into main Mar 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant