Skip to content

Commit 018d5da

Browse files
authored
[Bugfix] make invokeai-batch work on windows (#3164)
- Previous PR to truncate long filenames won't work on windows due to lack of support for os.pathconf(). This works around the limitation by hardcoding the value for PC_NAME_MAX when pathconf is unavailable. - The `multiprocessing` send() and recv() methods weren't working properly on Windows due to issues involving `utf-8` encoding and pickling/unpickling. Changed these calls to `send_bytes()` and `recv_bytes()` , which seems to fix the issue. Not fully tested on Windows since I lack a GPU machine to test on, but is working on CPU.
2 parents 4d62d5b + 96a5de3 commit 018d5da

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

ldm/invoke/dynamic_prompts.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ def expand_prompts(
100100
for command in commands:
101101
sequence += 1
102102
format = _get_fn_format(outdir, sequence)
103-
parent_conn.send(
104-
command + f' --fnformat="{format}"'
103+
parent_conn.send_bytes(
104+
(command + f' --fnformat="{format}"').encode('utf-8')
105105
)
106106
parent_conn.close()
107107
else:
@@ -116,7 +116,10 @@ def _get_fn_format(directory:str, sequence:int)->str:
116116
Get a filename that doesn't exceed filename length restrictions
117117
on the current platform.
118118
"""
119-
max_length = os.pathconf(directory,'PC_NAME_MAX')
119+
try:
120+
max_length = os.pathconf(directory,'PC_NAME_MAX')
121+
except:
122+
max_length = 255
120123
prefix = f'dp.{sequence:04}.'
121124
suffix = '.png'
122125
max_length -= len(prefix)+len(suffix)
@@ -130,7 +133,7 @@ def __init__(self, connection: Connection):
130133
def readline(self) -> str:
131134
try:
132135
if len(self.linebuffer) == 0:
133-
message = self.connection.recv()
136+
message = self.connection.recv_bytes().decode('utf-8')
134137
self.linebuffer = message.split("\n")
135138
result = self.linebuffer.pop(0)
136139
return result

0 commit comments

Comments
 (0)