Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a process in a keybinding fails #229

Open
1 of 2 tasks
noughtmare opened this issue Jul 18, 2020 · 4 comments
Open
1 of 2 tasks

Creating a process in a keybinding fails #229

noughtmare opened this issue Jul 18, 2020 · 4 comments

Comments

@noughtmare
Copy link

noughtmare commented Jul 18, 2020

Problem Description

Creating a process in a keybinding fails. I know this can be fixed by using
xfork, but I would like to know why it does not work like this.

See this reddit thread.

Configuration File

{-# LANGUAGE TypeApplications #-}
module Main (main) where

import XMonad
import System.Process (readProcess)
import Control.Monad (void)
import Data.Map (singleton)
import Control.Exception (try, SomeException)

main :: IO ()
main = xmonad def
  { keys = \cfg ->
      singleton
        (modMask cfg, xK_a)
        (io $ do
          x <- try @SomeException (readProcess "dmenu" [] "")
          case x of
            Left e -> spawn ("xmessage \"Error: " ++ show e ++ "\"")
            Right _ -> spawn "xmessage Good!")
      <> keys def cfg
  }

This first starts dmenu normally then after you press enter (or escape) it opens an xmessage window with the text:

Error: waitForProcess: does not exist (No child processes)

Checklist

xmonad-testing does not seem to be up-to-date anymore? I've tested this with xmonad 0.15 from Hackage.

@geekosaur
Copy link
Contributor

geekosaur commented Jul 18, 2020 via email

@noughtmare
Copy link
Author

Thanks for the quick reply.

Am I right when I conclude from your response that avoiding freezing the window manager is the main reason for disabling child processes? In that case wouldn't you want to restrict the X monad even more, so that you can only do non-blocking IO? Keybindings could be changed to the type IO (X ()) such that they are always xforked and the resulting X action is only executed when the IO action finishes. I think that would be even safer. But maybe this is too complicated.

It is also not very good at 'reaping' child processes, because you can still start dmenu without problems, it only returns an error code when the process finishes. That still means that Xmonad is frozen for an indefinite amount of time.

@geekosaur
Copy link
Contributor

geekosaur commented Jul 20, 2020 via email

@noughtmare
Copy link
Author

I meant more like having the IO action executed in a background thread that returns an X action that can be put on some kind of queue to be executed in the main Xmonad thread. But, I see that there are still many other problems with such an approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants