RuntimeError: dictionary changed size during iteration
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 158
Description
File "D:\ComfyUI\ComfyUI\main.py", line 224, in
loop.run_until_complete(run(server, address=args.listen, port=args.port, verbose=not args.dont_print_server, call_on_start=call_on_start))
File "asyncio\base_events.py", line 653, in run_until_complete
File "D:\ComfyUI\ComfyUI\main.py", line 128, in run
await asyncio.gather(server.start(address, port, verbose, call_on_start), server.publish_loop())
File "D:\ComfyUI\ComfyUI\server.py", line 611, in publish_loop
await self.send(*msg)
File "D:\ComfyUI\ComfyUI\server.py", line 544, in send
await self.send_image(data, sid=sid)
File "D:\ComfyUI\ComfyUI\server.py", line 581, in send_image
await self.send_bytes(BinaryEventTypes.PREVIEW_IMAGE, preview_bytes, sid=sid)
File "D:\ComfyUI\ComfyUI\server.py", line 587, in send_bytes
for ws in self.sockets.values():
RuntimeError: dictionary changed size during iteration
I've a client, endless uploading images to comfyui Server. Then this error will occur every now and then.
I think this is a bug, that server didn't protect thread safety.
My upload function is like:
` self.originImage1Path = utils.uploadImage2Comfy(image1Path, targetPort= self.targetPort)
self.maskImage2Path = utils.uploadImage2Comfy(image2Path, targetPort= self.targetPort)
self.styleImage3Path = utils.uploadImage2Comfy(image3Path, targetPort= self.targetPort)
`
`def uploadImage2Comfy(imagePath, targetPort):
while True:
try:
url = LOCAL_REQUEST_URL + ":" + str(targetPort) + "/upload/image" # 更新为你的 API url
data = {}
files = {'image': open(imagePath, 'rb')}
resp = requests.post(url, files=files, data=data)
if resp.status_code == 200:
data = resp.json()
path = data.get('name')
if data.get('subfolder'):
path = data['subfolder'] + "/" + path
return path
else:
print(resp.status_code, resp.text)
except Exception as error:
print(error)
time.sleep(1)`
is there a fix for server.py? or how can I alternate my code to avoid this runtimeerror?
Contributor guide
Assessment
This issue has not been assessed yet.