All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ondrej Mosnacek <omosnace@redhat.com>
To: Stephen Smalley <sds@tycho.nsa.gov>
Cc: SElinux list <selinux@vger.kernel.org>
Subject: Re: [PATCH userspace] sepolicy: generate man pages in parallel
Date: Fri, 18 Oct 2019 09:44:11 +0200	[thread overview]
Message-ID: <CAFqZXNsMVm2OmWOTiMaKybkhX8Zerp6rDeFfEd0UwhZRiNuNXQ@mail.gmail.com> (raw)
In-Reply-To: <d6755428-b0bd-1d88-69f7-0dd953eb7300@tycho.nsa.gov>

On Thu, Oct 17, 2019 at 7:15 PM Stephen Smalley <sds@tycho.nsa.gov> wrote:
> On 10/14/19 4:06 AM, Ondrej Mosnacek wrote:
> > Generating man pages takes a lot of time. Do it in parallel to speed up
> > the process.
> >
> > Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
>
> Acked-by: Stephen Smalley <sds@tycho.nsa.gov>

Thank you for the ack, however I discovered that after this change it
becomes more difficult to end the program via KeyboardInterrupt
(SIGINT). The first interrupt only stops the main process and you need
to send several more to take down the background processes as well...

I found a different way (multiprocessing.Pool) to do the same, which
ends the processing gracefully on interrupt, but that one behaves even
worse under Python 2 (each interrupt only cancels one work item and
the processing happily continues...). Since there are plans to support
only Python 3 in 3.0+ this may not be an issue, but I could also add a
few lines to fallback to sequential execution under Python 2 for the
sake of compatibility. Would that be OK or should I not bother?

Either way I'd like to send a v2 that uses multiprocessing instead of
concurrent.futures, so please don't merge this yet :)

FYI, here is a preliminary diff for a switch to multiprocessing.Pool:
https://github.com/WOnder93/selinux/commit/a33acec8c298c112f5412b8b61b5b09058a267ee

...and here is what the Python 2 fallback would look like:
https://github.com/WOnder93/selinux/commit/b39a12120656b50eb0a1ee01227646ba3cd63f15

>
> > ---
> >   python/sepolicy/sepolicy.py | 14 ++++++++++----
> >   1 file changed, 10 insertions(+), 4 deletions(-)
> >
> > diff --git a/python/sepolicy/sepolicy.py b/python/sepolicy/sepolicy.py
> > index 1934cd86..02094013 100755
> > --- a/python/sepolicy/sepolicy.py
> > +++ b/python/sepolicy/sepolicy.py
> > @@ -25,6 +25,7 @@ import os
> >   import sys
> >   import selinux
> >   import sepolicy
> > +from concurrent.futures import ProcessPoolExecutor
> >   from sepolicy import get_os_version, get_conditionals, get_conditionals_format_text
> >   import argparse
> >   PROGNAME = "policycoreutils"
> > @@ -326,8 +327,13 @@ def gen_gui_args(parser):
> >       gui.set_defaults(func=gui_run)
> >
> >
> > +def manpage_work(domain, path, root, source_files, web):
> > +    from sepolicy.manpage import ManPage
> > +    m = ManPage(domain, path, root, source_files, web)
> > +    print(m.get_man_page_path())
> > +
> >   def manpage(args):
> > -    from sepolicy.manpage import ManPage, HTMLManPages, manpage_domains, manpage_roles, gen_domains
> > +    from sepolicy.manpage import HTMLManPages, manpage_domains, manpage_roles, gen_domains
> >
> >       path = args.path
> >       if not args.policy and args.root != "/":
> > @@ -340,9 +346,9 @@ def manpage(args):
> >       else:
> >           test_domains = args.domain
> >
> > -    for domain in test_domains:
> > -        m = ManPage(domain, path, args.root, args.source_files, args.web)
> > -        print(m.get_man_page_path())
> > +    with ProcessPoolExecutor() as e:
> > +        for domain in test_domains:
> > +            e.submit(manpage_work, domain, path, args.root, args.source_files, args.web)
> >
> >       if args.web:
> >           HTMLManPages(manpage_roles, manpage_domains, path, args.os)
> >
>


-- 
Ondrej Mosnacek <omosnace at redhat dot com>
Software Engineer, Security Technologies
Red Hat, Inc.


  reply	other threads:[~2019-10-18  7:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-14  8:06 [PATCH userspace] sepolicy: generate man pages in parallel Ondrej Mosnacek
2019-10-17 17:14 ` Stephen Smalley
2019-10-18  7:44   ` Ondrej Mosnacek [this message]
2019-10-18  9:00     ` Chris PeBenito
2019-10-18  9:01       ` Chris PeBenito
2019-10-18  9:22         ` Ondrej Mosnacek

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=CAFqZXNsMVm2OmWOTiMaKybkhX8Zerp6rDeFfEd0UwhZRiNuNXQ@mail.gmail.com \
    --to=omosnace@redhat.com \
    --cc=sds@tycho.nsa.gov \
    --cc=selinux@vger.kernel.org \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.