Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions examples/reproducer/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
set -e

tesseract --loglevel debug build .

docker system prune --force

tesseract run reproducer apply '{"inputs":{}}' --output-path outputs
Copy link
Contributor

@johnbcoughlin johnbcoughlin Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're going to commit this example let's name it something more specific, like process-pool-executor-reproducer

39 changes: 39 additions & 0 deletions examples/reproducer/tesseract_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from concurrent.futures import ProcessPoolExecutor

import numpy as np
from pydantic import BaseModel


class InputSchema(BaseModel):
pass


class OutputSchema(BaseModel):
pass


# FIXME: if pool.submit uses a function defined in tesseract_api.py
# we get a pickling error: module tesseract_api not found.
def preprocess_fn(data_id: int):
print(data_id, "processing")
return data_id


def apply(inputs):
data_ids = list(range(10))

pool = ProcessPoolExecutor()
futures = []

for idx in data_ids:
# this causes the pickling error
# x = pool.submit(preprocess_fn, idx)
x = pool.submit(np.identity, idx)
futures.append(x)
print(idx, "submitted")

for f in futures:
res = f.result()
print(res, "done")

return OutputSchema()
2 changes: 2 additions & 0 deletions examples/reproducer/tesseract_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: "reproducer"
version: "0.0.1"
23 changes: 15 additions & 8 deletions tesseract_core/runtime/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ def __init__(self, *sinks: Callable) -> None:
super().__init__()
self._sinks = sinks
self._fd_read, self._fd_write = os.pipe()
self._pipe_reader = os.fdopen(self._fd_read)
self._pipe_reader = os.fdopen(self._fd_read, closefd=False)
self._captured_lines = []
self._lock = threading.Lock()

def __enter__(self) -> int:
"""Start the thread and return the write file descriptor of the pipe."""
Expand All @@ -32,13 +33,19 @@ def __enter__(self) -> int:

def __exit__(self, *args: Any) -> None:
"""Close the pipe and join the thread."""
os.close(self._fd_write)
# Use a timeout so something weird happening in the logging thread doesn't
# cause this to hang indefinitely
self.join(timeout=10)
# Do not close reader before thread is joined since there may be pending data
# This also closes the fd_read pipe
self._pipe_reader.close()
with self._lock:
os.close(self._fd_write)

# Use a timeout so something weird happening in the logging thread doesn't
# cause this to hang indefinitely
#
# FIXME: this always times out in the multiprocessing case?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this with timeout=1, 10, and no timeout and the reproducer had no error, but this timeout is going to vary depending on the time it takes run to execute.

Should we add a warning here so that we can revise the timeout later if we frequently find an issue with the timeout, or set it to something even longer?

if self.is_alive():
    warn.warning("LogPipe thread timed out while executing.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the FIXME, it works for me?

self.join(timeout=1)

# Do not close reader before thread is joined since there may be pending data
# This also closes the fd_read pipe
os.close(self._fd_read)
self._pipe_reader.close()

def fileno(self) -> int:
"""Return the write file descriptor of the pipe."""
Expand Down
Loading