How to check if turtle is running yet?

50 views
Skip to first unread message

Adorilson

unread,
Mar 16, 2026, 9:03:05 AMMar 16
to brython
Hi, folks.

This is my first email (and question) here.
I'm a Brazilian professor and Phd student, and I'm developing a web environment to teach programming.

We are using Brython, and turtle is a central feature of my proposal.

Besides running the student code, I would like to check if it is correct.

If I have the code following:

```
for _ in range(4):
    turtle.forward(200)
    turtle.left(90)

print('End.')
```

'End.' will print before the square is done.

Here, I have two problems:
1. It sounds weird to a newbie to see a command result before the previous ones finished

2. How do I run the suite test only after the code's work is really done?

Is there an out-of-the-box solution for it? Is it possible to make turtle synchronous?

If not, what is the more suitable solution for "discover" if the turtle has done its work?

[]'s
--
Adorilson

Denis Migdal

unread,
Mar 17, 2026, 1:04:24 AMMar 17
to bry...@googlegroups.com
You want to use Brython in REPL mode ?

--
You received this message because you are subscribed to the Google Groups "brython" group.
To unsubscribe from this group and stop receiving emails from it, send an email to brython+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/brython/d1c9da9f-aaeb-49c6-865f-420a1c5ce623n%40googlegroups.com.

Denis Migdal

unread,
Mar 17, 2026, 2:45:48 AMMar 17
to brython
Did you tried turtle.done() and screen.updated() ?

Adorilson

unread,
Mar 19, 2026, 3:24:06 PMMar 19
to bry...@googlegroups.com
Em ter., 17 de mar. de 2026 às 06:45, Denis Migdal <denis....@gmail.com> escreveu:
Did you tried turtle.done() and screen.updated() ?

Yeah. And it isn't on the REPL.

The "problem" is that Brython creates a SVG which is rendered only after the "turtle.done()". 

Currently, I am binding a custom command in the end event of the "last" animation tag.

 Thank you.



--
Adorilson Bezerra

Atenção: Este e-mail pode conter anexos no formato ODF (Open Document Format)/ABNT
(extensões odt, ods, odp, odb, odg). Antes de pedir os anexos em outro formato, você pode
instalar gratuita e livremente o LibreOffice (http://libreoffice.org/)

Denis Migdal

unread,
Mar 20, 2026, 1:13:59 AMMar 20
to bry...@googlegroups.com
How I see.

I assume this is due to turtle implementation in Brython.
Indeed, JS can't wait synchronously (e.g. sleep).

Maybe we could have a kind of :
JS.whenEndOfTimers( () => { do_stuff } ) ?

ben levitt

unread,
Mar 20, 2026, 1:44:07 AMMar 20
to bry...@googlegroups.com
It looks like the demo here: https://brython.info/gallery/turtle.html manages to animate.  Maybe you could start from that?

Ben


Adorilson

unread,
Mar 23, 2026, 5:49:49 PM (13 days ago) Mar 23
to bry...@googlegroups.com
Em sex., 20 de mar. de 2026 às 05:14, Denis Migdal <denis....@gmail.com> escreveu:
How I see.

I assume this is due to turtle implementation in Brython.
Indeed, JS can't wait synchronously (e.g. sleep).

Maybe we could have a kind of :
JS.whenEndOfTimers( () => { do_stuff } ) ?

Yeah. To be more concrete, currently there is something like:

```python
g3 = document.querySelector('#turtle-canvas g:nth-child(3)')
animate = g3.lastChild.lastChild
animate.bind('endEvent', lambda ev: custom_command(params))
```

pitfall: the SVG tags (attributes' name case and some values) created by Firefox are different from those created by Chromium.  

Ed

unread,
Mar 23, 2026, 6:58:56 PM (13 days ago) Mar 23
to bry...@googlegroups.com
The simple way is to just set a callback.  Use browser.timer.set_timeout (a thin wrapper around js function setTimeout) to suspend your code while turtle updates the canvas.  For fast operations, 100ms should be enough but adjust as needed:

from browser import timer
for _ in range(4):
    turtle.forward(200)
    turtle.left(90)

def callback () :
    print('End.')
browser.timer.set_timeout (callback, 100)

not as elegant as detecting when turtle is done.  but usually good enough.
there are also some animation frame functions in browser.timer.  never used them, don't know if they would help.


--
Reply all
Reply to author
Forward
0 new messages