Pure: How to disable background processes started by pure?

Created on 5 Jul 2016  ·  14Comments  ·  Source: sindresorhus/pure

Hi!
First things first: I fell in love you’re theme on first sight. It’s just neat. :)

There is just one thing I’m experiencing. Every time I'm closing a session in iTerm2 it prompts me with the following message:

This window is running the following jobs: cat and zsh.

My questions are: What causes this message? What feature(s) would I loose when I somehow disable this? And finally: how can I disable this?
Of course I could ask iTerm to not prompt me for running processes but most likely I’d close to many tabs accidentally then. ;)

Thanks for your help!

Most helpful comment

Glad you're enjoying the theme, wedi!

Now, what you're experiencing is an unfortunate side-effect of using zpty for async work processing (via zsh-async).

iTerm is reacting to the fact that a second zsh instance (a clone, if you will) is running inside zpty. Furthermore, the async worker uses coproc cat as a way to synchronize output between multiple async tasks so that their output isn't garbled.

I have not researched in-depth for a solution, but a workaround is not using Cmd+W. Instead Ctrl+D or typing exit at the console since a clean exit won't trigger the prompt.

would I loose when I somehow disable this?

You would essentially lose the git functionality for checking the remote for changes (git fetch) and if your current working tree is dirty (git status).

how can I disable this?

Add this at the end of your .zshrc, after initializing pure with prompt pure.

async_stop_worker prompt_pure
async_job() { }

Without the worker running, neither is the second zsh and cat. And by overriding the async_job function as a no-op, you won't see errors like: async_job:zpty:4: no such pty command: prompt_pure.

Another alternative would be using Terminal instead of iTerm, it does not react to the zpty processes, but does prevent you from accidentally stopping a terminal with a regular command running. Yet another option would be to report this upstream on the iTerm issue tracker.

All 14 comments

Glad you're enjoying the theme, wedi!

Now, what you're experiencing is an unfortunate side-effect of using zpty for async work processing (via zsh-async).

iTerm is reacting to the fact that a second zsh instance (a clone, if you will) is running inside zpty. Furthermore, the async worker uses coproc cat as a way to synchronize output between multiple async tasks so that their output isn't garbled.

I have not researched in-depth for a solution, but a workaround is not using Cmd+W. Instead Ctrl+D or typing exit at the console since a clean exit won't trigger the prompt.

would I loose when I somehow disable this?

You would essentially lose the git functionality for checking the remote for changes (git fetch) and if your current working tree is dirty (git status).

how can I disable this?

Add this at the end of your .zshrc, after initializing pure with prompt pure.

async_stop_worker prompt_pure
async_job() { }

Without the worker running, neither is the second zsh and cat. And by overriding the async_job function as a no-op, you won't see errors like: async_job:zpty:4: no such pty command: prompt_pure.

Another alternative would be using Terminal instead of iTerm, it does not react to the zpty processes, but does prevent you from accidentally stopping a terminal with a regular command running. Yet another option would be to report this upstream on the iTerm issue tracker.

Hi mafredri,
thank you for your prompt and in-depth answer on that topic!

As disabling the background process would cut pure too much for me I won’t go that route but maybe that helps someone else searching for this topic.

So I tried CRTL+D which logs me cleanly out of a ssh session to a server (where I’m using bash) but zsh on my Mac just tells me to "use logout to logout" instead. :(

As the _Terminal.app_ is no option compared to _iTerm2_ I’d love to get this solved upstream. I’d be glad if you could help me reporting this. I drafted a report maybe you could have a quick look at it wether I understood things correctly? Maybe you could even help me with arguing why it’s a bug and no feature? ;) They are also asking for steps to reproduce. Would it be too big a request if I asked you for a short example to add to the bug report?

Thank you!

Hello!
I am using the pure ZSH-Prompt theme which uses the zsh-built-in module zpty to make asynchronous calls to git.
_zpty:_

is useful for running commands non-interactively which expect an interactive environment.

While Apple’s _Terminal.app_ ignores the second zsh process started by ´zpty´ when closing the window _iTerm2_ aks me if I really want to close that tab.

This tab is running the following jobs: cat and zsh.

I think iTerm2 should ignore that process as well.

From iTerm2s new issue template:

_Detailed steps to reproduce the problem:_



    1. 2.
  1. 3.

_What happened:_
When closing a session the following message pops up:

This window is running the following jobs: cat and zsh.

_What should have happened:_
The session should close without prompting because ...

thank you for your prompt and in-depth answer on that topic!

You're welcome, and I wish to point out that @sindresorhus is the original creator of the theme, if it wasn't for him I wouldn't be contributing to it ^_^.

So I tried CRTL+D which logs me cleanly out of a ssh session to a server (where I’m using bash) but zsh on my Mac just tells me to "use logout to logout" instead. :(

Weird. You could try loading a different preset for your keys in Profiles -> Keys.

Maybe you could even help me with arguing why it’s a bug and no feature? ;)

I would love to, but I don't know enough about what's happening to do that :/. Maybe it's Terminal that's at fault, maybe iTerm, or maybe it's just a difference in opinion. But obviously zpty does something that is regarded differently in Terminal and iTerm.

They are also asking for steps to reproduce. Would it be too big a request if I asked you for a short example to add to the bug report?

Not at all, easy to reproduce when running zsh:

  1. Open a new terminal with zsh as default shell
  2. Run: zmodload zsh/zpty; zpty -b test cat
  3. Hit Cmd+W

I just re-remembered a realization I had on this topic a long time back when investigating: zpty is not running as a child-job to the current shell, it's simply a child process, and maybe this is where iTerm errs from Terminal. You could also hint at that zpty is a module of zsh (the current shell) and shouldn't be considered an independent process?

I just re-remembered a realization I had on this topic a long time back when investigating

Yeah, I think you should go with this line of reasoning, I just created another repro:

  1. Open a shell with zsh as default shell
  2. Run sleep 10 &!
  3. Hit Cmd+W

This also prompts for sleep, but sleep has been disowned and is completely irrelevant to the running shell.

Thanks! But there must be something different to the sleep because when I run sleep 10 &! in _Terminal.app_ it prompts

If you close the window, these running processes will get terminated: -zsh, cat, sleep

(My own translation from German)

BTW: CTRL-D doesn’t work in the _Terminal.app_ as well.

I filed this issue on the _iTerm2_ tracker:
https://gitlab.com/gnachman/iterm2/issues/4895

Seems you are correct. So that doesn't explain the issue, and after a bit more digging I still can't figure out what the difference between a zpty process in Terminal and a disowned one is. Let's hope the issue gives us some more insight into the matter, good job on writing it up 👍 !

BTW: CTRL-D doesn’t work in the _Terminal.app_ as well.

Ah, you should go into Profiles -> Shell -> When the shell exits: and select Close if the shell exited cleanly.

BTW: CTRL-D doesn’t work in the Terminal.app as well.
Ah, you should go into Profiles -> Shell -> When the shell exits: and select Close if the shell exited cleanly.

I have already activated that. I think it’s ZSH itself. See this screenshot: screenshot

This message appears after pressing CTRL+D in _Terminal.app_ as well as _iTerm2_. When using the logout command both close without prompting – with the pure prompt theme activated and with sleep in the background (sleep 30 &!) btw.

Careful with what setopts you enable 😜.

unsetopt ignoreeof

On Wed, 6 Jul 2016, 2:02 a.m. Dirk Weise, [email protected] wrote:

BTW: CTRL-D doesn’t work in the Terminal.app as well.

Ah, you should go into Profiles -> Shell -> When the shell exits: and
select Close if the shell exited cleanly.

I have already activated that. I think it’s ZSH itself. See this
screenshot: [image: screenshot]
https://cloud.githubusercontent.com/assets/1466269/16602453/81755c72-4314-11e6-8a86-4c061b34cd7c.png

This message appears after pressing CTRL+D in _Terminal.app_ as well as
_iTerm2_. When using the logout command both close without prompting –
with the pure prompt theme activated and with sleep in the background (sleep
30 &!) btw.


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/sindresorhus/pure/issues/215#issuecomment-230627793,
or mute the thread
https://github.com/notifications/unsubscribe/AAI_0YUyb_vEEivCUNUx7KekCfVXNNAQks5qSuJwgaJpZM4JFa1Q
.

Just found the reason for that, too. :see_no_evil:

And now closing the session via CMD+W works in iTerm2 as well without any prompt. :flushed: :flushed: :see_no_evil:

That still does not explain the differences to _Terminal.app_ but at least my current annoyance is gone.

thank you so much for you help! 👍

It’s too late. I need to got to bed. This did not solve the issue. I just forgot I implemented a workaround. I told _iTerm2_ to ignore the processes zsh and cat when prompting:
Screenshot

@wedi I just pushed a new commit to https://github.com/mafredri/zsh-async/commit/db5651d87c809e1c317d86a5cb1cf34b5322a9e8 that removes the need for you to include cat in the excluded process list. It would be much appreciated if you could try it out :).

Leaving the processes running always bothered me (especially cat), so I think this is an improvement!

Since 1.4.0 has now been released, I'm closing this seeing as we have done everything we can to fix this issue, this release includes the updated zsh-async which removes cat from the running background processes whenever possible.

Sorry we couldn't fully fix this @wedi, let's hope for some happy news from the iTerm dev team in the near future :).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sudo-nice picture sudo-nice  ·  6Comments

ELLIOTTCABLE picture ELLIOTTCABLE  ·  11Comments

harukizaemon picture harukizaemon  ·  10Comments

Hotschke picture Hotschke  ·  8Comments

jpresley23 picture jpresley23  ·  8Comments