-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: run blocking call in threadpool #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
playwright/_impl/_browser_context.py
Outdated
@@ -298,8 +299,7 @@ async def _pause(self) -> None: | |||
async def storage_state(self, path: Union[str, Path] = None) -> StorageState: | |||
result = await self._channel.send_return_as_dict("storageState") | |||
if path: | |||
with open(path, "w") as f: | |||
json.dump(result, f) | |||
await async_writefile(path, "w", json.dumps(result)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was already leaving this comment, should be async_write_file(page, json.dumps(result))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay but how would you write in binary with this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OR you mean we should have two functions for writing one for str and one for bytes ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async_write_file
would accept Union[str, bytes]
and will pick the right mode.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Thanks for confirming
playwright/_impl/_browser.py
Outdated
@@ -214,5 +215,4 @@ def normalize_context_params(is_sync: bool, params: Dict) -> None: | |||
if "storageState" in params: | |||
storageState = params["storageState"] | |||
if not isinstance(storageState, dict): | |||
with open(storageState, "r") as f: | |||
params["storageState"] = json.load(f) | |||
params["storageState"] = json.loads(await async_read_text(storageState)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(await async_read_file()).decode()
playwright/_impl/_element_handle.py
Outdated
@@ -241,8 +242,7 @@ async def screenshot( | |||
decoded_binary = base64.b64decode(encoded_binary) | |||
if path: | |||
make_dirs_for_file(path) | |||
with open(path, "wb") as fd: | |||
fd.write(decoded_binary) | |||
await async_writefile(path, "wb", decoded_binary) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
playwright/_impl/_file_chooser.py
Outdated
file_payloads.append( | ||
{ | ||
"name": os.path.basename(item), | ||
"buffer": base64.b64encode(await async_read_binary(item)).decode(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async_read_file
playwright/_impl/_helper.py
Outdated
await loop.run_in_executor(None, inner) | ||
|
||
|
||
async def async_read_binary(file: Union[str, Path]) -> bytes: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async_read_file
playwright/_impl/_helper.py
Outdated
|
||
|
||
async def async_read_text(file: Union[str, Path]) -> str: | ||
return (await async_read_binary(file)).decode() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline this, no reason to have a separate function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
No description provided.