# terminal: Move PTY spawning to the background thread and retain exit status \(\#58004\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/b32570d931a3073cddf7e1a44740dc21d2e20f9f)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: b32570d931a3073cddf7e1a44740dc21d2e20f9f

Requested commit: b32570d931a3073cddf7e1a44740dc21d2e20f9f

Commit: b32570d931a3073cddf7e1a44740dc21d2e20f9f

Tree: 9eb9737287a480553aaca453aa6d227ef0c15d54

Author: Anthony Eid

Committer: GitHub

## Message

```
terminal: Move PTY spawning to the background thread and retain exit status (#58004)

This PR does two things 

1. Move PTY child spawning to the background executor. Forking to spawn
the terminal child was taking between 10-70ms on profiles I was looking
at, which caused frames to be dropped because it was on the foreground
thread. This should fix issues such as #57574 where the miniprof from
this comment showed terminal creation blocking the foreground thread as
well.
https://github.com/zed-industries/zed/issues/57574#issuecomment-4546858817

2. Stopped overwriting alacrities exit status with `9` on
`AlacTermEvent::Exit` event handling. Before we get the exit event,
alacritty emits `ChildExit(status)` with the real status, which we used
to overwrite with exit status 9 when handling the AlacTermEvent::Exit.
This was an easy fix so I added it in this PR when I noticed the bug.


Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Closes #ISSUE

Release Notes:

- fixed dropped frames caused by agents or users creating new terminals
```

## Parents

- [59d8766f35afdbe74678d4ac3bca86ed582c864e](https://git.cafe/gitcafe/zed/commit/59d8766f35afdbe74678d4ac3bca86ed582c864e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/b32570d931a3073cddf7e1a44740dc21d2e20f9f?format=markdown)
