| Module | Pygments::Popen |
| In: |
lib/pygments/popen.rb
|
Check for a @pid variable, and then hit `kill -0` with the pid to check if the pid is still in the process table. If this function gives us an ENOENT or ESRCH, we can also safely return false (no process to worry about). Defensively, if EPERM is raised, in a odd/rare dying process situation (e.g., mentos is checking on the pid of a dead process and the pid has already been re-used) we‘ll want to raise that as a more informative Mentos exception.
Returns true if the child is alive.
Public: Highlight code.
Takes a first-position argument of the code to be highlighted, and a second-position hash of various arguments specifiying highlighting properties.
Get things started by opening a pipe to mentos (the freshmaker), a Python process that talks to the Pygments library. We‘ll talk back and forth across this pipe.
Stop the child process by issuing a kill -9.
We then call waitpid() with the pid, which waits for that particular child and reaps it.
kill() can set errno to ESRCH if, for some reason, the file is gone; regardless the final outcome of this method will be to set our @pid variable to nil.
Technically, kill() can also fail with EPERM or EINVAL (wherein the signal isn‘t sent); but we have permissions, and we‘re not doing anything invalid here.