semaphore + react
Browse files
app.py
CHANGED
@@ -19,6 +19,8 @@ from pytz import timezone
|
|
19 |
#
|
20 |
import asyncio
|
21 |
|
|
|
|
|
22 |
zurich_tz = timezone("Europe/Zurich")
|
23 |
|
24 |
def convert_to_timezone(dt, tz):
|
@@ -52,7 +54,8 @@ async def deepfloydif(ctx, *, prompt: str):
|
|
52 |
|
53 |
def check_reaction(reaction, user):
|
54 |
return user == ctx.author and str(reaction.emoji) in ['1️⃣', '2️⃣', '3️⃣', '4️⃣']
|
55 |
-
|
|
|
56 |
|
57 |
number_of_images = 4
|
58 |
current_time = int(time.time())
|
@@ -142,8 +145,10 @@ async def dfif2(ctx, index: int, stage_1_result_path):
|
|
142 |
print(f"Error: {e}")
|
143 |
await ctx.reply('An error occurred while processing stage 2 upscaling. Please try again later.')
|
144 |
#----------------------------------------------------------------------------------------------------------------------------
|
145 |
-
|
146 |
-
|
|
|
|
|
147 |
|
148 |
|
149 |
|
|
|
19 |
#
|
20 |
import asyncio
|
21 |
|
22 |
+
semaphore = asyncio.Semaphore(1) # for concurrent tasks
|
23 |
+
|
24 |
zurich_tz = timezone("Europe/Zurich")
|
25 |
|
26 |
def convert_to_timezone(dt, tz):
|
|
|
54 |
|
55 |
def check_reaction(reaction, user):
|
56 |
return user == ctx.author and str(reaction.emoji) in ['1️⃣', '2️⃣', '3️⃣', '4️⃣']
|
57 |
+
|
58 |
+
await ctx.message.add_reaction('👍')
|
59 |
|
60 |
number_of_images = 4
|
61 |
current_time = int(time.time())
|
|
|
145 |
print(f"Error: {e}")
|
146 |
await ctx.reply('An error occurred while processing stage 2 upscaling. Please try again later.')
|
147 |
#----------------------------------------------------------------------------------------------------------------------------
|
148 |
+
async def process_dfif2(ctx, index, stage_1_result_path):
|
149 |
+
async with semaphore:
|
150 |
+
await dfif2(ctx, index, stage_1_result_path)
|
151 |
+
#----------------------------------------------------------------------------------------------------------------------------
|
152 |
|
153 |
|
154 |
|