Terminating a process on Windows

I’m not able to kill a Julia process on Windows. Instead, its status remains as ProcessSignaled, and it never terminates. The issue doesn’t exist on MacOS and Linux, and it occurs regardless of Julia version. I didn’t experience this issue last month, and I’m beginning to suspect that this is related to a recent Windows 10 update. Still, I thought I would reach out to the community, in case I am doing something silly (besides shelling out in the first place!).

Minimal nonworking example

# This command runs silently and terminates on its own
command = "sleep(5)"
# This command prints to the REPL and must be signaled
#command =  "while true; print(\"-\"); sleep(1); end"

process = run(pipeline(`julia -e $command`, stdout), wait=false);

# Important: On Windows, this may create a process that doesn't terminate!

This thread seems be related.

I found this workaround:

  # Command for drawing a spinner
  command = "
    t=Threads.@async read(stdin, Char)
    while !istaskdone(t)
      for q=['\\\\','|','/','-']

  # Draw spinner as a separate process
  proc_input = Pipe();
  proc = run(pipeline(`julia -e $command`,stdin = proc_input, stdout = stdout), wait = false)

  kill(proc) # Process is signaled, but it keeps running
  write(proc_input,'c') # Process finishes when it reads from its stdin

Instead of relying on kill(), the main process writes to the stdin of the spawned process, and this is interpreted as a sort of kill signal.

In practice, the main drawback is that I haven’t found any way for the spawned process to receive signals both from the user and from the main process.