....
from multiprocessing import Process, Queue
....
....
async def screenshot(stock, loop, date_msg):
await launch(headless=True, defaultViewport=None, args=['--no-sandbox'])
.....
await page.screenshot({'path': os.path.join(BASEDIR, stock+".png")})
.....
if (....):
return data
else:
return 0
....
loop = asyncio.get_event_loop()
@client.on_message()
def msg_handler(client, message):
global loop
....
if message.caption is not None:
result = re.findall(r'\w{1,6}\s+\w{1}\s+\d+\,*\d+\s+\d+\,*\d+\s+\d+\,*\d+', message.caption)
if len(result):
def make_screens(queue, result):
....
screens = []
for row in result:
date_msg = .......
stock = .......
....
loop1 = asyncio.new_event_loop()
asyncio.set_event_loop(loop1)
loop = asyncio.get_event_loop()
data = loop.run_until_complete(screenshot(stock.upper(), loop, date_msg))
if data:
screens.append(InputMediaPhoto(os.path.join(BASEDIR, stock.upper()+".png")))
.......
queue.put(screens)
queue = Queue()
p = Process(target=make_screens, args=(queue, result))
p.start()
p.join()
screens = queue.get()