From: Alexander Turenko <alexander.turenko@tarantool.org> To: Stanislav Zudin <szudin@tarantool.org> Cc: Vladimir Davydov <vdavydov.dev@gmail.com>, tarantool-patches@freelists.org, Georgy Kirichenko <georgy@tarantool.org> Subject: Re: [tarantool-patches] Re: [PATCH v2] core: Non-blocking io.popen Date: Wed, 5 Jun 2019 06:49:25 +0300 [thread overview] Message-ID: <20190605034919.pxotvzn5lvzraxvv@tkn_work_nb> (raw) In-Reply-To: <20190604075931.w3y5th6k7b7b7v4a@esperanza> On Tue, Jun 04, 2019 at 10:59:31AM +0300, Vladimir Davydov wrote: > On Tue, Jun 04, 2019 at 10:11:15AM +0300, Stanislav Zudin wrote: > > > > > > On 03.06.2019 20:25, Alexander Turenko wrote: > > > > > Come to think of it, we might need an explicit knob to destroy an object > > > > > even before it's collected. May be, consider re-adding close() for this? > > > > > Please consult with Alexander and/or Georgy re this. > > > > > > > > > > > > > Sasha, George, what do you think? > > > > > > I'm a bit out of context. Why we need explicit close()? To control > > > reaching a file descriptor limit? It can be worked around with > > > `handle = nil collectgarbage()`, but an explicit close() looks better. > > > Maybe it worth to add. > > > > > > > For now there is wait() as a final method. It waits for process termination > > and releases resources. > > We might want to read process output after waiting for it to complete. > Or it doesn't make any sense? I imagine this in the following way. One way to implement the API is to map C/Unix API to work with child processes / pipes in more or less direct way and so wait() just waits for a process to terminate, read() / write() performs operations on a pipe internal buffer. The only significant differences are proper integration with our event loop and providing helpful popen handle that accumulate all related file descriptors and information fields. Another way is to hide deeper real process and pipes under our abstractions: wait() expects both a process termination and pipes closing, while read() / write() performs operations on buffers in our memory and hide real read() / write(), which is performed in background. This way is safer in the sense of a pipe buffer size exceeding, but provides less control over using memory for buffers (they can take a large memory). If we'll going the first way it seems natural to allow to do read() after wait() and provide close() to free resources manually. The second way allows to read everything to the end in wait() and only then really close pipes. Both ways should allow a user to perform API's read() after wait(), the difference only when we actually call close() on a pipe. I don't see a reason to make things more complex then they are and I would consider popen implementation as the thin layer between Lua and Unix API. But maybe I mix aspects of the API that should be considered separately, don't sure. > > > So the question was: should we add close() to release resources > > explicitly? > > Anyway there is a finalizer who performs a final cleanup for the case when > > user forgot to do it. > > To trigger the finalizer, we need to delete the variable > > p = nil > > which isn't very user friendly IMO. I think explicit close() is needed for applications that want to carefully manage system resources. Say, you writing a harness (runner) for tests and each run calls popen. You can run hundreds processes per second and GC may be not aggressive enough to save you from, say, open file descriptor limit. One can tune GC options or manually call collectgarbage(), but is looks more as the workaround rather then solutions for the problem.
next prev parent reply other threads:[~2019-06-05 3:49 UTC|newest] Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-29 7:08 Stanislav Zudin 2019-05-30 18:34 ` Vladimir Davydov 2019-05-31 8:13 ` [tarantool-patches] " Konstantin Osipov 2019-06-03 15:52 ` Stanislav Zudin 2019-06-03 17:25 ` Alexander Turenko 2019-06-04 7:11 ` Stanislav Zudin 2019-06-04 7:59 ` Vladimir Davydov 2019-06-05 3:49 ` Alexander Turenko [this message] 2019-06-04 11:14 ` Vladimir Davydov 2019-06-04 22:39 ` Alexander Turenko 2019-05-31 11:49 ` Vladimir Davydov 2019-05-31 17:32 ` [tarantool-patches] " Konstantin Osipov 2019-05-31 17:49 ` Vladimir Davydov 2019-06-03 15:53 ` Stanislav Zudin
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190605034919.pxotvzn5lvzraxvv@tkn_work_nb \ --to=alexander.turenko@tarantool.org \ --cc=georgy@tarantool.org \ --cc=szudin@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [tarantool-patches] Re: [PATCH v2] core: Non-blocking io.popen' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox