�
�
â €2021-11-21 13:08:10
Asynchronous programming
â €, 2021-11-21 13:08:10

How to perform an asynchronous function call in Python?

I want to write a prank for friends related to the gradual dimming of the screen. The code:

import pyautogui
from win32gui import SetPixel, GetDC
from pywintypes import error
from win32api import RGB
from random import randint as rnd

color = (0, 0, 0)
dc = GetDC(0)

def effect(dc, x, y, color):
    SetPixel(dc, x, y, color)

for times in range(1000):
    s = pyautogui.screenshot()
    for x in range(s.width):
        for y in range(s.height):
            if s.getpixel((x, y)) == color:
                try:
                    effect(dc, x + rnd(1, 10), y + rnd(1, 10), RGB(color[0], color[1], color[2]))
                except error:
                    pass

Pixel drawing is very slow, how can I fix this?

EDIT : How does the code work?
A screenshot is taken and black is searched for. When a location in x and y is found, another black pixel is drawn next to it, like in viruses.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antonio Solo, 2021-11-21
@AndromedaZ

Pixel drawing is very slow, how can I fix this?

render in memory, use libraries that work with cv2 arrays, numpy ...
and what does asynchrony have to do with it? speeding up python code with asynchrony will not work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question