Maxximiliann
defmodule PythonProcessAPI do
require Logger
def process_output(foo, _, python_path) do
Print.text("Results received from #{python_path}.")
Logger.info("#{inspect(foo)}, __MODULE__, line 8")
end
def connect(data, python_path) do
port =
:erlang.open_port(
{:spawn, python_path},
[:binary, packet: 4]
)
execute = fn input ->
send(port, {self(), {:command, :erlang.term_to_binary({input})}})
receive do
foo ->
process_output(foo, data, python_path)
end
end
execute.(data)
end
end
#my_python_process.py
import sys
import simplejson as json
from loguru import logger
from conversion import to_string
from erlastic import port_connection, Atom as atom
from some_library.errors import (BaseError, AuthenticationError, PermissionDenied,
ArgumentsRequired, BadRequest, BadResponse,
NullResponse, InvalidAddress, NotSupported, NetworkError, DDoSProtection,
RateLimitExceeded, OnMaintenance, InvalidNonce, RequestTimeout)
mailbox, port = port_connection()
@logger.catch
def submit_report(success_status, report, arg1, arg2, arg3):
logger.info("Processing report . . . ")
full_report = report | {
'arg1': arg1, 'arg2': arg2, 'arg3': arg3}
full_report_json = json.dumps(full_report)
try:
port.send((atom(success_status), (full_report_json)))
logger.info("Transmitted report . . . ")
except (BrokenPipeError) as error:
logger.exception(error)
sys.exit()
finally:
sys.exit()
@logger.catch
def fetch_params():
for params_data in mailbox:
params_hash = to_string(params_data)
return params_hash[0]
@logger.catch
def some_function():
params_json = fetch_params()
params = json.loads(params_json)
arg1, arg2, arg3 = params
try:
submission_report = some_operation(params)
except (BaseError, AuthenticationError, PermissionDenied,
ArgumentsRequired, BadRequest, BadResponse,
NullResponse, InvalidAddress, NotSupported, NetworkError, DDoSProtection,
RateLimitExceeded, OnMaintenance, InvalidNonce, RequestTimeout) as error:
logger.exception(error)
logger.info(params)
submit_report(
'error', {'error': str(error)}, arg1, arg2, arg3)
except Exception as crash_report:
logger.exception(crash_report)
logger.info(params)
submit_report('error', {'error': str(
crash_report)}, arg1, arg2, arg3)
else:
submit_report(
'ok', submission_report, arg1, arg2, arg3)
@ logger.catch
def main():
some_function()
if __name__ == '__main__':
main()
The problem we’re having is that data can be passed to the Python process successfully but the return message never reaches the Elixir side. All success messages from the Python end are logged, but there are no exceptions or error messages to go on. We’re at a loss for how to diagnose what’s wrong. Suggestions? Recommendations?
Trending in Questions
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
Hello,
I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind.
However, when I launch mix phx.server, I get an error...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New
I’m working on a small exercise involving update_in/3, and I came up with this solution:
data = %{
name: "Periodic Table",
category:...
New
Other Trending Topics
Edit: 2026 May 15 - This post is archived.
Mob is alive!!
Main docs: mob v0.7.11 — Documentation
A bit of explanation for the slightly c...
New
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
A little off-topic, but I feel like people here have a good head on their shoulders.
I used to be quite good at making software. Was luc...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ai
- #ecto-query
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #metaprogramming
- #hex










Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
derek-zhou
Can’t comment on the python side.
You are only handling one message in the elixir side. Is it intentional? Maybe the message is still in the inbox. try flush() in iex.
kokolegorille
Can’t comment on erlastic, but I have been using erlport lately with python.
This blog post is really nice…
https://medium.com/stuart-engineering/how-we-use-python-within-elixir-486eb4d266f9