Skip to content

Support Windows #45

@asmacdo

Description

@asmacdo

Duct works by creating a new session to run all processes under.

I didn't look into this too deeply, but it does look possible. Still, I wouldnt feel comfortable just adding this until we test for the abandoning parent issue, blocked by: #44

From ChatGPT:

**For Windows, os.setsid is not available as it is specific to Unix-like systems. Instead, you can use subprocess.CREATE_NEW_PROCESS_GROUP in combination with Popen to achieve similar functionality. This flag creates a new process group, which allows you to manage the process more effectively.

Here is an example of how you can modify your Popen call to work on both Unix-like systems and Windows:

import os
import subprocess
import platform

def start_process(command):
    if platform.system() == "Windows":
        # Windows-specific implementation
        process = subprocess.Popen(command, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP)
    else:
        # Unix-like system implementation
        process = subprocess.Popen(command, preexec_fn=os.setsid)
    return process

# Example usage
command = ["your_command", "arg1", "arg2"]
process = start_process(command)

This code will check the operating system and use the appropriate flag for creating a new process group. On Unix-like systems, it uses os.setsid, and on Windows, it uses subprocess.CREATE_NEW_PROCESS_GROUP. This should provide a functional equivalent to os.setsid for process management on Windows.**

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions