-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jarek/7718: url arg accessible from notebook python (#7800)
* #7718: getting url args for python * #7718: solve problem with killing the app by CTRL+C * #7718: add type to UrlArgBody
- Loading branch information
1 parent
f68329b
commit 345b26e
Showing
7 changed files
with
307 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Copyright 2018 TWO SIGMA OPEN SOURCE, LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import socket | ||
import zmq | ||
import threading | ||
|
||
|
||
class BeakerxZMQServer: | ||
|
||
def __init__(self, beakerXQueue): | ||
self.queue = beakerXQueue | ||
self.url = "tcp://127.0.0.1:" + BeakerxZMQServer.get_free_tcp_port() | ||
thread = threading.Thread(target=self.threaded_function, daemon=True) | ||
thread.start() | ||
|
||
def threaded_function(self): | ||
context = zmq.Context() | ||
socket = context.socket(zmq.REP) | ||
socket.bind(self.url) | ||
while True: | ||
message = socket.recv() | ||
self.queue.put(message) | ||
socket.send_string("Ok") | ||
|
||
@staticmethod | ||
def get_free_tcp_port(): | ||
tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
tcp.bind(('localhost', 0)) | ||
addr, port = tcp.getsockname() | ||
tcp.close() | ||
return str(port) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.