from threading import Thread, Lock
import logging
import webview
from time import sleep
from server import run_server

server_lock = Lock()

logger = logging.getLogger(__name__)


def url_ok(url, port):
    # Use httplib on Python 2
    try:
        from http.client import HTTPConnection
    except ImportError:
        from httplib import HTTPConnection

    try:
        conn = HTTPConnection(url, port)
        conn.request('GET', '/')
        r = conn.getresponse()
        return r.status == 200
    except:
        logger.exception('Server not started')
        return False

if __name__ == '__main__':
    logger.debug('Starting server')
    t = Thread(target=run_server)
    t.daemon = True
    t.start()
    logger.debug('Checking server')

    while not url_ok('127.0.0.1', 23948):
        sleep(1)

    logger.debug('Server started')
    window = webview.create_window('My first pywebview application', 'http://127.0.0.1:23948')
    webview.start(debug=True)

@@ -1,12 +1,106 @@
+import logging%0Aimport webview%0A%0Afrom contextlib import redirect_stdout%0Afrom io import StringIO%0A
 from threadi
@@ -126,38 +126,8 @@
 ock%0A
-import logging%0Aimport webview%0A
 from
@@ -667,16 +667,79 @@
 ain__':%0A
+%0A    stream = StringIO()%0A    with redirect_stdout(stream):%0A    
     logg
@@ -766,16 +766,20 @@
 erver')%0A
+    
     t = 
@@ -804,16 +804,20 @@
 server)%0A
+    
     t.da
@@ -828,16 +828,20 @@
  = True%0A
+    
     t.st
@@ -846,16 +846,20 @@
 start()%0A
+    
     logg
@@ -891,16 +891,20 @@
 ')%0A%0A    
+  
+  
 while no
@@ -933,16 +933,20 @@
 23948):%0A
+    
         
@@ -955,16 +955,20 @@
 eep(1)%0A%0A
+    
     logg
@@ -990,24 +990,28 @@
 r started')%0A
+    
     window =
@@ -1093,16 +1093,20 @@
 23948')%0A
+    
     webv

Fix Flask example to allow freezing