# Pipe closing

**URL:** <https://discourse.julialang.org/t/pipe-closing/9397>\
**Category:** Internals & Design\
**Created:** [February 28, 2018, 8:49pm UTC](https://discourse.julialang.org/t/pipe-closing/9397 "2018-02-28T20:49:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 28, 2018, 8:49pm UTC](https://discourse.julialang.org/t/pipe-closing/9397/1 "2018-02-28T20:49:11Z")

</div>

Consider the 0.6 code:

```julia
pin = Base.Pipe()
...
Base.close_pipe_sync(pin.out)

```

This does not work in 0.7: one must pass in pin.out.handle, appropriately converted to either `WindowsRawSocket` or `RawFD`. The dependence on the OS thus spreads from stream.jl to user code.

Is this something that is this way for a reason, or is that a bug?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 28, 2018, 9:31pm UTC](https://discourse.julialang.org/t/pipe-closing/9397/2 "2018-02-28T21:31:47Z")

</div>

> [@PetrKryslUCSD](#):
>
> The dependence on the OS thus spreads from stream.jl to user code.

You are talking about “user code” that calls an internal undocumented `Base` function. What is wrong with `close(pin)`?

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 28, 2018, 9:37pm UTC](https://discourse.julialang.org/t/pipe-closing/9397/3 "2018-02-28T21:37:07Z")

</div>

What if you don’t want to close both in and out?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 28, 2018, 9:47pm UTC](https://discourse.julialang.org/t/pipe-closing/9397/4 "2018-02-28T21:47:35Z")

</div>

> [@PetrKryslUCSD](#):
>
> What if you don’t want to close both in and out?

The best you can do right now is e.g. `close(Base.pipe_writer(pin))`, I think. `Base.pipe_reader` and `Base.pipe_writer` are still undocumented internal functions at the moment, but at least they are higher-level functions that don’t expose pipe internals.

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [February 28, 2018, 9:48pm UTC](https://discourse.julialang.org/t/pipe-closing/9397/5 "2018-02-28T21:48:39Z")

</div>

That sounds like a great suggestion. Thanks!

---

<div class="post-metadata">

**Author:** ![jameson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jameson/32/23_2.png) [@jameson](https://discourse.julialang.org/u/jameson)\
**Post date:** [February 28, 2018, 11:24pm UTC](https://discourse.julialang.org/t/pipe-closing/9397/6 "2018-02-28T23:24:49Z")

</div>

> [@stevengj](#):
>
> but at least they are higher-level functions that don’t expose pipe internals.

If you know you have a `Pipe()` object precisely, `.in` and `.out` are shorter to type. In an unusual variation, the `pipe_writer` / `pipe_reader` functions currently expose the internal implementation detail of `AbstractPipe`, and thus may actually be a bit less high-level than the using the field names themselves directly.
