sdwebui-w-horde / sd-webui-stable-horde-worker

Stable Horde Unofficial Worker Bridge as Stable Diffusion WebUI (AUTOMATIC1111) Extension
GNU Affero General Public License v3.0
60 stars 18 forks source link

Execute in a separate thread #110

Closed Maeyanie closed 5 months ago

Maeyanie commented 1 year ago

Description

The changes in 9edcf3bb7048115292107aba3e1e4ae18e1a25b7, at least for my setup (Conda, Python 3.10, Win10) resulted in horde.run() running async, but still in the main thread. This mostly worked, but caused the whole WebUI to block while horde.run() wasn't sleeping.

I tried a couple of things, and this is what ended up working best for me, with a lot of the functions in the loop being async and it not being possible to use await in a non-async function. Moving the thread function somewhere else might be more elegant, I don't know your code well enough to know where would be best to put it though.

Type of changes

Please check the following items before submitting your pull request

MaikoTan commented 1 year ago

Looks good. But I can only see there is a .start() method, so when does the thread terminate?

By the way, we are trying to replace aiohttp and all asyncio things into synchronous API with requests in #102 , would it solve the block issue without touching thread?

Maeyanie commented 1 year ago

The thread would terminate when the process is terminated, effectively the same as before.

I'm not sure if that would help or not, I'm more of a C++ programmer than a Python one. My guess would be no, due to the nature of how event queues work, but it would be better to test it to find out for sure.

It would probably change the best approach to using a thread, though, so if that's coming reasonably soon it may be better not to merge this and wait to see how things turn out.