diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2017-03-30 22:26:42 +0300 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2017-03-30 22:26:42 +0300 |
| commit | 51923dcf0dd38638183c444d608f94df60f0226d (patch) | |
| tree | 55607acac321ac20bbdd1292556a7c262c2b0947 | |
| parent | 73e93d043705966f4ccd835e49a91b11987fd9bf (diff) | |
Add print lockmaster
| -rwxr-xr-x | client.py | 13 | ||||
| -rwxr-xr-x | server.py | 1 |
2 files changed, 10 insertions, 4 deletions
@@ -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": @@ -12,6 +12,7 @@ PORT = 5000 DEBUG = True running = True + def debug(string): if (DEBUG): print("{} DEBUG: {}".format(datetime.now(), string)) |
