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 & InitPython
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.
- This section has 6 entries; this is one of them.
- See the full section index: Recipes
Other entries in this section
- Batch undo groupWrap big jobs in BeginCommandGroup / EndCommandGroup and one Ctrl+Z in
- Set font, read back, then fall backSee the code below. This is the most valuable pattern in the entire sc
- Verify the font before converting to curvesConverting to curves is irreversible, so the order is fixed: set the f
- Process in index-range batchesWith a lot of JSON records, run start/end slices and print "total / pa
- Skip missing data instead of raisingif not img_find_in: skip_cnt += 1; continue — a missing image gets cou