-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththread_db.py
More file actions
executable file
·33 lines (27 loc) · 824 Bytes
/
thread_db.py
File metadata and controls
executable file
·33 lines (27 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from threading import Thread
import random
import time
running = True
class DatabaseServer(Thread):
"""process imaginary database requests"""
def run(self):
"""
Whatever is in the run method (or called from
it, is executed in a separate thread
"""
while running:
sec = random.randint(10, 20)
print('Processing database request for', sec, 'seconds')
time.sleep(sec)
print('Finished processing database request')
print('mp has requested the database server stop running.')
thread = DatabaseServer()
thread.start()
while True:
text = input('Enter some text: ')
if text == 'qqq':
running = False
while thread.is_alive():
pass
break
print(text[::-1], 'deretne uoY ')