Repository: microsoft/playwright-python

Issue:
[Fix] sys.stderr.fileno() throws an AttributeError exception
When I tried to delivered the playwright tasks via `celery==4.4.7`, I got an `AttributeError` exception at line 50 in `main.py`. 

`except AttributeError:`

I've checked the source from `pytest`, the original code is:

 ```
     except (AttributeError, io.UnsupportedOperation):
            # pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
            # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
            # This is potentially dangerous, but the best we can do.
            return sys.__stderr__.fileno()
```

It perfectly works if I changed it to the original code, so I think we should be consistent with the original source code to enhance compatibility.

I also checked the celery official docs. The reason why I got an `AttributeError` exception probably is that the log proxy of celery is not support the `stderr` attribute.

[Fix] sys.stderr.fileno() throws an AttributeError exception
When I tried to delivered the playwright tasks via `celery==4.4.7`, I got an `AttributeError` exception at line 50 in `main.py`. 

`except AttributeError:`

I've checked the source from `pytest`, the original code is:

 ```
     except (AttributeError, io.UnsupportedOperation):
            # pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
            # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
            # This is potentially dangerous, but the best we can do.
            return sys.__stderr__.fileno()
```

It perfectly works if I changed it to the original code, so I think we should be consistent with the original source code to enhance compatibility.

I also checked the celery official docs. The reason why I got an `AttributeError` exception probably is that the log proxy of celery is not support the `stderr` attribute.



Discussion:
@Evilran did you try it locally after adding `AttributeError` to your local `playwright/main.py` and did it work?

Sounds good to me that we can add it.
@mxschmitt I did that before and it works as expected! I think it would be nice if you could change it in the next stable version of `playwright-python` package 👍 
> @mxschmitt I did that before and it works as expected! I think it would be nice if you could change it in the next stable version of `playwright-python` package 👍

Cool thanks for confirming, will adjust it.
@Evilran did you try it locally after adding `AttributeError` to your local `playwright/main.py` and did it work?

Sounds good to me that we can add it.
@mxschmitt I did that before and it works as expected! I think it would be nice if you could change it in the next stable version of `playwright-python` package 👍 
> @mxschmitt I did that before and it works as expected! I think it would be nice if you could change it in the next stable version of `playwright-python` package 👍

Cool thanks for confirming, will adjust it.

Resolving patch:
diff --git a/playwright/main.py b/playwright/main.py
--- a/playwright/main.py
+++ b/playwright/main.py
@@ -43,11 +43,11 @@ def compute_driver_executable() -> Path:
 async def run_driver_async() -> Connection:
     driver_executable = compute_driver_executable()
 
-    # Sourced from: https://github.com/pytest-dev/pytest/blob/49827adcb9256c9c9c06a25729421dcc3c385edc/src/_pytest/faulthandler.py#L73-L80
+    # Sourced from: https://github.com/pytest-dev/pytest/blob/824e9cf67abcfc47df25a59bf32ebd8c25fbd02a/src/_pytest/faulthandler.py#L70-L77
     def _get_stderr_fileno() -> int:
         try:
             return sys.stderr.fileno()
-        except io.UnsupportedOperation:
+        except (AttributeError, io.UnsupportedOperation):
             # pytest-xdist monkeypatches sys.stderr with an object that is not an actual file.
             # https://docs.python.org/3/library/faulthandler.html#issue-with-file-descriptors
             # This is potentially dangerous, but the best we can do.


Test patch: