Skip to content

Commit

Permalink
exit-ref
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisrink10 committed Nov 22, 2024
1 parent 7bc8e7f commit 5f9fde2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/basilisp/process.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,22 @@
(ex-info "Expected a file-like or path-like object"
{:file f :opts opts}))))

(defn exit-ref
"Given a :external:py:class:`subprocess.Popen` (such as the one returned by
:lpy:fn:`start`), return a reference which can be used to wait (optionally with
timeout) for the completion of the process."
[process]
(reify
basilisp.lang.interfaces/IBlockingDeref
(deref [_ & args]
(let [[timeout-ms timeout-val] args]
(if timeout-ms
(try
(.wait process ** :timeout (/ timeout-ms 1000))
(catch subprocess/TimeoutExpired _
timeout-val))
(.wait process))))))

(defn ^:private wrapped-file-context-manager
"Wrap a potential file in a context manager for ``start``.
Expand Down

0 comments on commit 5f9fde2

Please sign in to comment.