-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSurgeryRoom.py
45 lines (39 loc) · 1.18 KB
/
SurgeryRoom.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
from Location import Location
from patient import Patient
import threading
class SurgeryRoom(threading.Thread):
def __init__(self, id):
self.id = id
self.is_used = False
self.surgery_stopped = True
self.doctors_number = 0
self.patient: Patient = None
self.doctors = []
self.lock = threading.Lock()
def take_room(self, patient, doctors):
self.lock.acquire()
try:
self.surgery_stopped = False
self.doctors = doctors
self.patient = patient
self.doctors_number = len(self.doctors)
self.is_used = True
for doctor in self.doctors:
doctor.surgery_room = self
finally:
self.lock.release()
def stop_surgery(self):
self.surgery_stopped = True
def start_surgery(self):
self.surgery_stopped = False
def complete_surgery(self):
self.lock.acquire()
try:
self.is_used = False
self.patient = None
self.doctors = []
self.patient = None
except:
pass
finally:
self.lock.release()