Test threading lock
This commit is contained in:
@@ -4,12 +4,13 @@ import websocket
|
||||
import json
|
||||
import yaml
|
||||
import random
|
||||
import threading
|
||||
|
||||
__version__ = "2.0.0b1"
|
||||
__version__ = "2.0.0b2"
|
||||
versionstring='Taurix TellMe server v' + __version__
|
||||
|
||||
app = Flask(__name__)
|
||||
# socketio = SocketIO(app, async_mode='gevent')
|
||||
lock = threading.Lock()
|
||||
|
||||
hooks = {}
|
||||
with open(r'/etc/tellme/hooks.yml') as hooksfile:
|
||||
@@ -17,25 +18,25 @@ with open(r'/etc/tellme/hooks.yml') as hooksfile:
|
||||
|
||||
def sendmessage(target, message):
|
||||
print("Sendmessage %s called to %s" % (message, target))
|
||||
#message = "#Bottest Hello, world!"
|
||||
msg = ("%s %s" % (target, message))
|
||||
with lock:
|
||||
msg = ("%s %s" % (target, message))
|
||||
|
||||
# Create a unique correlation ID
|
||||
command = {
|
||||
"corrId": f"id{random.randint(0, 999999)}",
|
||||
"cmd": msg,
|
||||
}
|
||||
json_command = json.dumps(command)
|
||||
# Create a unique correlation ID
|
||||
command = {
|
||||
"corrId": f"id{random.randint(0, 999999)}",
|
||||
"cmd": msg,
|
||||
}
|
||||
json_command = json.dumps(command)
|
||||
|
||||
""" Connects to WebSocket server, sends a message, and returns the response """
|
||||
uri = "ws://localhost:5080"
|
||||
ws = websocket.create_connection(uri) # Blocking WebSocket connection
|
||||
ws.send(json_command) # Send message to WebSocket
|
||||
response = ws.recv() # Receive response
|
||||
# ws.close() # Close WebSocket connection
|
||||
# print(response)
|
||||
ws.close()
|
||||
return response
|
||||
""" Connects to WebSocket server, sends a message, and returns the response """
|
||||
uri = "ws://localhost:5080"
|
||||
ws = websocket.create_connection(uri) # Blocking WebSocket connection
|
||||
ws.send(json_command) # Send message to WebSocket
|
||||
response = ws.recv() # Receive response
|
||||
# ws.close() # Close WebSocket connection
|
||||
# print(response)
|
||||
ws.close()
|
||||
return response
|
||||
|
||||
@app.route("/webhook/<id>", methods=['POST'])
|
||||
def webhook_receiver(id):
|
||||
|
||||
Reference in New Issue
Block a user