Skip to content

Commit 072f00c

Browse files
committed
cleanup asyncio windows proactor
1 parent 980d0d9 commit 072f00c

File tree

8 files changed

+19
-29
lines changed

8 files changed

+19
-29
lines changed

examples/demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import asyncio
2828
import sys
2929
from argparse import ArgumentParser
30-
from asyncioffmpeg.runner import runner
3130

3231

3332
async def coro_worker(i: int, Niter: int, tic: float):
@@ -97,7 +96,7 @@ def mp_worker(i: int, Niter: int, tic: float):
9796
ps.append(p)
9897

9998
if A.method == "c":
100-
runner(coro, A.Nworker, A.Niter, tic)
99+
asyncio.run(coro(A.Nworker, A.Niter, tic))
101100
elif A.method == "p":
102101
for p in ps:
103102
p.join()

examples/play_coroutine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python3
22
from argparse import ArgumentParser
3+
import asyncio
34

45
import asyncioffmpeg.ffplay as play
5-
from asyncioffmpeg.runner import runner
66
from asyncioffmpeg import get_videos
77

88

@@ -17,4 +17,4 @@
1717
flist = get_videos(P.path, P.suffix)
1818
print("found", len(flist), "files in", P.path)
1919

20-
runner(play.main, flist)
20+
asyncio.run(play.main(flist))

examples/probe_coroutine.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
"""
33
~ 4x speedup over ffprobe_sync
44
"""
5+
56
import time
67
from argparse import ArgumentParser
8+
import asyncio
79

810
import asyncioffmpeg.ffprobe as probe
9-
from asyncioffmpeg.runner import runner
1011

1112

1213
if __name__ == "__main__":
@@ -19,10 +20,10 @@
1920

2021
tic = time.monotonic()
2122
# %% emits results as each future is completed
22-
runner(probe.get_meta, P.path, P.suffix)
23+
asyncio.run(probe.get_meta(P.path, P.suffix))
2324
print(f"ffprobe asyncio.as_completed: {time.monotonic() - tic:.3f} seconds")
2425

2526
# %% approximately same wallclock time, but only gives results when all futures complete
2627
tic = time.monotonic()
27-
runner(probe.get_meta_gather, P.path, P.suffix)
28+
asyncio.run(probe.get_meta_gather(P.path, P.suffix))
2829
print(f"ffprobe asyncio.gather: {time.monotonic() - tic:.3f} seconds")

setup.cfg

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = asyncioffmpeg
3-
version = 1.2.0
3+
version = 1.2.1
44
author = Michael Hirsch, Ph.D.
55
author_email = scivision@noreply.users.github.com
66
url = https://github.com/scivision/asyncio-subprocess-ffmpeg
@@ -15,9 +15,7 @@ classifiers =
1515
Framework :: AsyncIO
1616
Intended Audience :: End Users/Desktop
1717
Operating System :: OS Independent
18-
Programming Language :: Python :: 3.7
19-
Programming Language :: Python :: 3.8
20-
Programming Language :: Python :: 3.9
18+
Programming Language :: Python :: 3
2119
Topic :: Multimedia :: Video :: Conversion
2220
Topic :: System :: Networking
2321
Topic :: Utilities
@@ -38,7 +36,7 @@ where=src
3836

3937
[options.extras_require]
4038
tests =
41-
pytest >= 3.9
39+
pytest
4240
lint =
4341
flake8
4442
flake8-bugbear

src/asyncioffmpeg/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from pathlib import Path
22
import typing as T
3+
import os
4+
import asyncio
5+
6+
if os.name == "nt":
7+
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
38

49

510
def get_videos(path: Path, suffixes: T.Sequence[str] = None) -> T.List[Path]:

src/asyncioffmpeg/ffprobe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async def ffprobe(file: Path) -> typing.Dict[str, typing.Any]:
5757
"-show_format",
5858
str(file),
5959
],
60-
stdout=asyncio.subprocess.PIPE
60+
stdout=asyncio.subprocess.PIPE,
6161
)
6262

6363
stdout, _ = await proc.communicate()

src/asyncioffmpeg/runner.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/asyncioffmpeg/tests/test_ffprobe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from pytest import approx
2+
import asyncio
23

34
import asyncioffmpeg.ffprobe as probe
4-
from asyncioffmpeg.runner import runner
55

66

77
def get_duration(meta: dict) -> float:
@@ -11,15 +11,15 @@ def get_duration(meta: dict) -> float:
1111
def test_ffprobe_as_completed(genpat):
1212
vid = genpat
1313

14-
metas = runner(probe.get_meta, vid.parent, [".avi", ".mp4"])
14+
metas = asyncio.run(probe.get_meta(vid.parent, [".avi", ".mp4"]))
1515
assert len(metas) == 1
1616
assert get_duration(metas[0]) == approx(5.0)
1717

1818

1919
def test_ffprobe_gather(genpat):
2020
vid = genpat
2121

22-
metas = runner(probe.get_meta_gather, vid.parent, [".avi", ".mp4"])
22+
metas = asyncio.run(probe.get_meta_gather(vid.parent, [".avi", ".mp4"]))
2323
assert len(metas) == 1
2424
assert get_duration(metas[0]) == approx(5.0)
2525

0 commit comments

Comments
 (0)