Абдикашева Вилена Ринатовна, 411 группа SyncSeq 17940
Алдабергенов Руслан Даниярович, 411 SyncSeq 17861
t1import asynciot1import asyncio
22
3class Seq:3class Seq:
4    _next_to_run = 04    _next_to_run = 0
5    _semaphores = []5    _semaphores = []
66
7    def __init__(self, ident):7    def __init__(self, ident):
8        self.name = ident8        self.name = ident
9        sem = asyncio.Semaphore(0 if len(Seq._semaphores) else 1)9        sem = asyncio.Semaphore(0 if len(Seq._semaphores) else 1)
10        Seq._semaphores.append(sem)10        Seq._semaphores.append(sem)
11        self.index = len(Seq._semaphores) - 111        self.index = len(Seq._semaphores) - 1
1212
13    async def run(self):13    async def run(self):
14        await Seq._semaphores[self.index].acquire()14        await Seq._semaphores[self.index].acquire()
15        print(self.name)15        print(self.name)
16        if self.index + 1 < len(Seq._semaphores):16        if self.index + 1 < len(Seq._semaphores):
17            Seq._semaphores[self.index + 1].release()17            Seq._semaphores[self.index + 1].release()
18        return self.name18        return self.name
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op