Home/ Reference/ Recipes

Throttling: why time.sleep(0.2) appears everywhere

CorelDRAW is a single-threaded STA server. Python issues commands far faster than CDR can redraw, and with no pause it crashes outright (0x8001010A busy, or CDR goes

Scenario

Throttling: why time.sleep(0.2) appears everywhere

Notes

CorelDRAW is a single-threaded STA server. Python issues commands far faster than CDR can redraw, and with no pause it crashes outright (0x8001010A busy, or CDR goes unresponsive). Rules of thumb: 0.2 s after a property change, 0.5 s after importing an image, 0.3 s after a font change — fonts land slowly, and 0.12 s reads the old value and reports a false failure.

Python example (runnable)

Requires pywin32. The example assumes app / doc / page / layer are already connected. See Connection & Init
Python
import time

layer = doc.ActivePage.ActiveLayer

# CorelDRAW is a single-threaded COM server; firing commands too fast makes it hang
for i in range(3):
    rect = layer.CreateRectangle2(i * 60/25.4, 0, 50/25.4, 50/25.4)
    time.sleep(0.2)                  # wait 0.2s after changing a property

layer.Import("D:/images/a.jpg", 0, None)
time.sleep(0.5)                      # importing an image is heavy, wait longer

About this section: Recipes

Recipes — copy-paste ready workflows.

Other entries in this section