Skip to content

Commit 4d62d5b

Browse files
authored
[Bugfix] detect running invoke before updating (#3163)
This PR addresses the issue that when `invokeai-update` is run on a Windows system, and an instance of InvokeAI is open and running, the user's `.venv` can get corrupted. Issue first reported here: https://discord.com/channels/1020123559063990373/1094688269356249108/1094688434750230628
2 parents 03274b6 + f95403d commit 4d62d5b

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

ldm/invoke/config/invokeai_update.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
'''
55
import os
66
import platform
7+
import psutil
78
import requests
89
from rich import box, print
9-
from rich.console import Console, Group, group
10+
from rich.console import Console, group
1011
from rich.panel import Panel
1112
from rich.prompt import Prompt
1213
from rich.style import Style
13-
from rich.syntax import Syntax
14-
from rich.text import Text
1514

1615
from ldm.invoke import __version__
1716

@@ -32,6 +31,19 @@
3231
def get_versions()->dict:
3332
return requests.get(url=INVOKE_AI_REL).json()
3433

34+
def invokeai_is_running()->bool:
35+
for p in psutil.process_iter():
36+
try:
37+
cmdline = p.cmdline()
38+
matches = [x for x in cmdline if x.endswith(('invokeai','invokeai.exe'))]
39+
if matches:
40+
print(f':exclamation: [bold red]An InvokeAI instance appears to be running as process {p.pid}[/red bold]')
41+
return True
42+
except psutil.AccessDenied:
43+
continue
44+
return False
45+
46+
3547
def welcome(versions: dict):
3648

3749
@group()
@@ -62,6 +74,10 @@ def text():
6274

6375
def main():
6476
versions = get_versions()
77+
if invokeai_is_running():
78+
print(f':exclamation: [bold red]Please terminate all running instances of InvokeAI before updating.[/red bold]')
79+
return
80+
6581
welcome(versions)
6682

6783
tag = None

0 commit comments

Comments
 (0)