Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a "sync" model that disables subprocesses #76

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 15 additions & 5 deletions deadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ def __init__(
shutdown_wait: Optional[bool] = None,
shutdown_cancel_futures: Optional[bool] = None,
daemon=True,
sync=False,
malloc_trim_rss_memory_threshold_bytes: Optional[int] = None,
) -> None:
super().__init__()
Expand Down Expand Up @@ -243,6 +244,7 @@ def __init__(
self.malloc_trim_rss_memory_threshold_bytes = (
malloc_trim_rss_memory_threshold_bytes
)
self.sync = sync

# TODO: overcommit
self.workers = SimpleQueue()
Expand Down Expand Up @@ -439,12 +441,20 @@ def submit(
raise PoolClosed("The pool is closed. No more tasks can be submitted.")

fut = Future()
self.submitted_jobs.put(
PrioritizedItem(
priority=deadpool_priority,
item=(__fn, args, kwargs, deadpool_timeout, fut),
if self.sync:
try:
result = __fn(*args, **kwargs)
except BaseException as e:
fut.set_exception(e)
else:
fut.set_result(result)
else:
self.submitted_jobs.put(
PrioritizedItem(
priority=deadpool_priority,
item=(__fn, args, kwargs, deadpool_timeout, fut),
)
)
)
return fut

def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None:
Expand Down
Loading