Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
83d23059
Commit
83d23059
authored
Feb 15, 2021
by
Jim Mussared
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tests/extmod: Add test for ThreadSafeFlag.
Signed-off-by:
Jim Mussared
<
jim.mussared@gmail.com
>
parent
cdf9c864
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
100 additions
and
0 deletions
+100
-0
tests/extmod/uasyncio_threadsafeflag.py
tests/extmod/uasyncio_threadsafeflag.py
+79
-0
tests/extmod/uasyncio_threadsafeflag.py.exp
tests/extmod/uasyncio_threadsafeflag.py.exp
+21
-0
No files found.
tests/extmod/uasyncio_threadsafeflag.py
0 → 100644
View file @
83d23059
# Test Event class
try
:
import
uasyncio
as
asyncio
except
ImportError
:
print
(
"SKIP"
)
raise
SystemExit
import
micropython
try
:
micropython
.
schedule
except
AttributeError
:
print
(
"SKIP"
)
raise
SystemExit
try
:
# Unix port can't select/poll on user-defined types.
import
uselect
as
select
poller
=
select
.
poll
()
poller
.
register
(
asyncio
.
ThreadSafeFlag
())
except
TypeError
:
print
(
"SKIP"
)
raise
SystemExit
async
def
task
(
id
,
flag
):
print
(
"task"
,
id
)
await
flag
.
wait
()
print
(
"task"
,
id
,
"done"
)
def
set_from_schedule
(
flag
):
print
(
"schedule"
)
flag
.
set
()
print
(
"schedule done"
)
async
def
main
():
flag
=
asyncio
.
ThreadSafeFlag
()
# Set the flag from within the loop.
t
=
asyncio
.
create_task
(
task
(
1
,
flag
))
print
(
"yield"
)
await
asyncio
.
sleep
(
0
)
print
(
"set event"
)
flag
.
set
()
print
(
"yield"
)
await
asyncio
.
sleep
(
0
)
print
(
"wait task"
)
await
t
# Set the flag from scheduler context.
print
(
"----"
)
t
=
asyncio
.
create_task
(
task
(
2
,
flag
))
print
(
"yield"
)
await
asyncio
.
sleep
(
0
)
print
(
"set event"
)
micropython
.
schedule
(
set_from_schedule
,
flag
)
print
(
"yield"
)
await
asyncio
.
sleep
(
0
)
print
(
"wait task"
)
await
t
# Flag already set.
print
(
"----"
)
print
(
"set event"
)
flag
.
set
()
t
=
asyncio
.
create_task
(
task
(
3
,
flag
))
print
(
"yield"
)
await
asyncio
.
sleep
(
0
)
print
(
"wait task"
)
await
t
asyncio
.
run
(
main
())
tests/extmod/uasyncio_threadsafeflag.py.exp
0 → 100644
View file @
83d23059
yield
task 1
set event
yield
wait task
task 1 done
----
yield
task 2
set event
yield
schedule
schedule done
wait task
task 2 done
----
set event
yield
task 3
task 3 done
wait task
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment