I’m experimenting with a new builtin goal (builtin...
# development
c
I’m experimenting with a new builtin goal (builtin because I want to access the scheduler in ways incompatible when running from a rule). However, breaking out of the Python code when it’s not executing a rule seems a bit unclean.
I just get:
Copy code
^C^CInterrupted by user:
(on the second
<ctrl>+<c>
) but nothing from what I can tell on the Python side (at least no output/cleanup)
That is, I’m running a long living process, and if the user wants to exit, then the pantsd pid is hanging and doesn’t shutdown cleanly.
Tried this:
Copy code
try:
        server.run()
    except KeyboardInterrupt:
        print("Closing...")
    except Exception as e:
        print("Something else", e)

    server.should_exit = True
but doesn’t seem to do what I want 😉
h
Behavior might be different with
--no-pantsd
if you haven't tried that
c
Right, that’s a good workaround until I figure this out.
Will try that.
Worked beautifully, thanks Eric.
❤️ 1
So, I can now access the full rule graph from a graphql backend api.. so far, I’ve only added a single query to it, but it works 😄
Copy code
{
  "data": {
    "targets": [
      "//.gitignore:files",
      "//BUILD_ROOT:files",
      "//cargo:scripts",
      "//pants.toml:files",
      "//pants:scripts",
      "3rdparty/jvm/com/fasterxml/jackson/core:jackson-databind",
      "3rdparty/jvm/com/fasterxml/jackson/datatype:jackson-datatype-jdk8",
      "3rdparty/jvm/com/github/javaparser:javaparser-symbol-solver-core",
      "3rdparty/jvm/io/circe:circe-generic",
....
🙌 1
w
ooh. that’s very neat.
meanwhile, Tom is using the BuiltinGoal infrastructure to add BSP support: so, great all around 😃
💯 1
@curved-television-6568: how Ctrl+C behaves will depend on how you created your
Session
c
It's a regular Pants invocation.. or are there options involved?
w
no, just how the BuiltinGoal infrastructure is being set up to get its
Session
c
Aahh.. that one. Ok, will look into it, thanks!
Hmm.. that cancellation latch, iiuc it merely sets a flag
is_canceled()
right? But if I never get to check that flag… what then? (trying to follow the startup sequence, but loose my trail going over the nailgun border to Rust land). Where do we enter Python land on the other side of the nailgun invocation?
I did spot the place in the Rust code responsible for handling my two ctrl+c’s, and issueing the kbd int on the second one.
w
SchedulerSession.execute
consumes the cancellation latch
so if your issue is that you’re blocking inside of that method, would need to figure out where
and then, why the cancellation signal isn’t making it
but loose my trail going over the nailgun border to Rust land
nailgun shouldn’t be important in this case: when the nailgun session is closing, the
Session
should get cancellation signaled, and then tear down in a few different places
and that shouldn’t change for a
BuiltinGoal
, unless the cancellation latch is not being propagated into the LocalPantsRunner to where the
BuiltinGoal
is being created
c
Yeah, I basically hang in a builtin goals run method
and don’t get any signals/exceptions to get out of there
c
I do see that the try catch for KeyboardInterrupt in local_pants_runner catches, though
w
the location that receives cancellation doesn’t change with/without
pantsd
the thing that does change, is that without
pantsd
all `Session`s are cancelled… and with
pantsd
, only the
Session
for a particular client is canceled
c
Oh… hmm… but isn’t the current running goal that particular client, then?
Ah, but that link, isn’t that for cancellation during a product request, i.e. execution of rules?
w
it all depends on how
LocalPantsRunner.create
sets things up. it is either called without its optional args (in which case it creates things from scratch), or with them (in which case it uses stuff from
pantsd
)
@curved-television-6568: yes. sorry, i thought you said that it was hung inside the scheduler
you won’t get a KeyboardInterrupt otherwise.
c
right, no, in the builtin goal’s run, so outside of rule execution
w
ah. so you’ll need to interact directly with the
Session
then probably.
c
right. So, trying to figure out how.. 🙂
w
you could poll
session.is_cancelled()
we can’t raise
KeyboardInterrupt
in arbitrary code, because it only raises on “the main thread”. it’s only raised while actually poking into code we control, e.g.
scheduler.execute
c
Mmm… yeah… might work. See if I can turn the
uvicorn
execution inside out, or somehow interrupt it’s main loop…
Thanks, that nudge should get me going a bit further..
w
sure thing.
🙌 1
c
Nailed it! 😄
🙄 1