Skip to content

Commit

Permalink
Merge pull request CompVis#20 from EyeDeck/master
Browse files Browse the repository at this point in the history
πŸ”₯ πŸ”₯ Workaround for Gradio server hanging on keyboard interrupt πŸ”₯ πŸ”₯  πŸ₯‡
  • Loading branch information
hlky authored Aug 25, 2022
2 parents a6f8080 + 5e9ed59 commit 94b73d8
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pynvml
import random
import threading
import threading, asyncio
import time
import torch
import torch.nn as nn
Expand Down Expand Up @@ -1010,5 +1010,28 @@ def run_GFPGAN(image, strength):
css=("" if opt.no_progressbar_hiding else css_hide_progressbar),
theme="default",
)

demo.queue(concurrency_count=1)
demo.launch(show_error=True, server_name='0.0.0.0')

class ServerLauncher(threading.Thread):
def __init__(self, demo):
threading.Thread.__init__(self)
self.name = 'Gradio Server Thread'
self.demo = demo

def run(self):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
demo.launch(show_error=True, server_name='0.0.0.0')

def stop(self):
demo.close() # this tends to hang

server_thread = ServerLauncher(demo)
server_thread.start()

try:
while server_thread.is_alive():
time.sleep(60)
except (KeyboardInterrupt, OSError) as e:
crash(e, 'Shutting down...')

0 comments on commit 94b73d8

Please sign in to comment.