Skip to content

Commit 3b87bca

Browse files
authored
chore(stderr): fix handling without stderr fileno (microsoft#402)
1 parent 63db2cf commit 3b87bca

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

playwright/_transport.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,25 @@
1313
# limitations under the License.
1414

1515
import asyncio
16+
import io
1617
import json
1718
import os
1819
import sys
1920
from pathlib import Path
20-
from typing import Dict
21+
from typing import Dict, Optional
22+
23+
24+
# Sourced from: https://github.com/pytest-dev/pytest/blob/da01ee0a4bb0af780167ecd228ab3ad249511302/src/_pytest/faulthandler.py#L69-L77
25+
def _get_stderr_fileno() -> Optional[int]:
26+
try:
27+
return sys.stderr.fileno()
28+
except (AttributeError, io.UnsupportedOperation):
29+
# pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
30+
# https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
31+
# This is potentially dangerous, but the best we can do.
32+
if not hasattr(sys, "__stderr__"):
33+
return None
34+
return sys.__stderr__.fileno()
2135

2236

2337
class Transport:
@@ -41,7 +55,7 @@ async def run(self) -> None:
4155
"run-driver",
4256
stdin=asyncio.subprocess.PIPE,
4357
stdout=asyncio.subprocess.PIPE,
44-
stderr=sys.stderr,
58+
stderr=_get_stderr_fileno(),
4559
limit=32768,
4660
)
4761
assert proc.stdout

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy