Skip to content

Instantly share code, notes, and snippets.

@weyou
Created February 8, 2023 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weyou/99ec44c6528ca814bdbb5bbcd67f82c2 to your computer and use it in GitHub Desktop.
Save weyou/99ec44c6528ca814bdbb5bbcd67f82c2 to your computer and use it in GitHub Desktop.
<button id="openModal">Open Modal</button>
<div id="modal" class="modal">
<div class="modal-content">
<span class="close">&times;</span>
<div class="iframe-container">
<iframe src="https://www.example.com/iframe1"></iframe>
<iframe src="https://www.example.com/iframe2"></iframe>
</div>
</div>
</div>
.modal {
display: none;
position: fixed;
z-index: 1;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: auto;
background-color: rgb(0,0,0);
background-color: rgba(0,0,0,0.4);
}
.modal-content {
background-color: #fefefe;
margin: 15% auto;
padding: 20px;
border: 1px solid #888;
width: 80%;
height: 80%;
}
.iframe-container {
display: flex;
}
.iframe-container iframe {
flex: 1;
width: 50%;
height: 100%;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: black;
text-decoration: none;
cursor: pointer;
}
let modal = document.getElementById("modal");
let openModal = document.getElementById("openModal");
let close = document.getElementsByClassName("close")[0];
openModal.addEventListener("click", () => {
modal.style.display = "block";
});
close.addEventListener("click", () => {
modal.style.display = "none";
});
window.addEventListener("click", event => {
if (event.target == modal) {
modal.style.display = "none";
}
});
@weyou
Copy link
Author

weyou commented Feb 13, 2023

reference: http://eyalarubas.com/python-subproc-nonblock.html

from threading import Thread

try:
from Queue import Queue, Empty
except ImportError:
from queue import Queue, Empty # python 3.x

class AsyncReader:

def __init__(self, stream, encoding, errors='strict'):
    '''
    stream: the stream to read from.
        Usually a process' stdout or stderr.
    '''
    self._s = stream
    self._q = Queue()
    self._errors = errors
    self._encoding = encoding

    self._t = Thread(target=self._populateQueue, args=(self._s, self._q))
    self._t.daemon = True
    self._t.start()  # start collecting lines from the stream

def _populateQueue(self, stream, queue):
    '''
    Collect lines from 'stream' and put them in 'quque'.
    '''
    while True:
        try:
            line = stream.readline().decode(self._encoding, self._errors)
        except UnicodeDecodeError:
            raise
        except Exception:
            return

        if line:
            queue.put(line)
        else:
            return  # EOF

def readline(self, timeout=None):
    """
    Return item or raise Empty exception immediately if timeout is None,
    otherwise, wait for that timeout and raise Empty exception if the
    item is not available.
    """
    try:
        line = self._q.get(block=timeout is not None, timeout=timeout)
        self._q.task_done()
    except Empty:
        if not self._t.is_alive():
            raise EndOfStream()
        return None

    return line

class EndOfStream(Exception):
pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment