aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jans.tuomi@gmail.com>2017-03-30 22:26:42 +0300
committerJan Tuomi <jans.tuomi@gmail.com>2017-03-30 22:26:42 +0300
commit51923dcf0dd38638183c444d608f94df60f0226d (patch)
tree55607acac321ac20bbdd1292556a7c262c2b0947
parent73e93d043705966f4ccd835e49a91b11987fd9bf (diff)
Add print lockmaster
-rwxr-xr-xclient.py13
-rwxr-xr-xserver.py1
2 files changed, 10 insertions, 4 deletions
diff --git a/client.py b/client.py
index f89112c..d3ad41a 100755
--- a/client.py
+++ b/client.py
@@ -21,12 +21,17 @@ BUFFER_SIZE = 1024
DEBUG = False
running = True
+print_lock = threading.Lock()
+def t_print(string):
+ with print_lock:
+ print(string)
+
def debug(string):
if (DEBUG):
- print("{} DEBUG: {}".format(datetime.now(), string))
+ t_print("{} DEBUG: {}".format(datetime.now(), string))
def signal_handler(signal, frame):
- print("Closing sockets and shutting down...")
+ t_print("Closing sockets and shutting down...")
global running
running = False
disconnect()
@@ -75,7 +80,7 @@ def listen_messages():
debug(body)
if username != nick:
timestamp = strftime("%H:%M:%S", gmtime())
- print("{} {}: {}".format(timestamp, username, body))
+ t_print("{} {}: {}".format(timestamp, username, body))
host = input("Host [{}]: ".format(DEFAULT_HOST))
nick = input("Nickname [{}]: ".format(DEFAULT_NICK))
@@ -96,7 +101,7 @@ kuuntelija = threading.Thread(target=listen_messages, args=())
kuuntelija.start()
#odotetaan kayttajan kirjoittavan viestin tai lopettavan ohjelman -quit-komennolla
-print("Type '-quit' to exit.")
+t_print("Type '-quit' to exit.")
while running:
syote = input()
if syote == "-quit":
diff --git a/server.py b/server.py
index 9e8ccf6..5e216f4 100755
--- a/server.py
+++ b/server.py
@@ -12,6 +12,7 @@ PORT = 5000
DEBUG = True
running = True
+
def debug(string):
if (DEBUG):
print("{} DEBUG: {}".format(datetime.now(), string))