Giter Site home page Giter Site logo

uriyyo / pycharm-evaluate-async-code Goto Github PK

View Code? Open in Web Editor NEW
42.0 5.0 1.0 346 KB

Finally, you can use await in evaluate expression ๐Ÿ’ช

Home Page: https://plugins.jetbrains.com/plugin/14476-evaluate-async-code

Kotlin 92.21% Python 7.79%
pycharm-plugin pycharm-ide pycharm asyncio python

pycharm-evaluate-async-code's Introduction

Hi there ๐Ÿ‘‹

Can you help me learn Haskell?

My OOP mind struggles every time I attempt to learn it ๐Ÿ˜ข

fibs = 0 : 1 : zipWith (+) fibs (tail fibs)

About me

I am a Software Engineer who mostly works with Python but used to work with C/C++ and Java a long time ago. Hope one day I will be able to understand Haskell (I have a dream to learn functional programming).

PEP 505 None-aware operators is a feature that I miss the most in Python.

I?.really?.want?.this?.feature ?? "Or not?"

Things done by me

FastAPI related

If you are using FastAPI and use function return type annotation as response_model you should know - I am the one who implemented it ๐Ÿ˜„ (FastAPI #1436).

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="Bio")


class Bio(BaseModel):
    name: str
    education: str
    languages: set[str]


@app.get("/me")
async def get_bio() -> Bio:
    return Bio(
        name="Yurii",
        education="Master's degree in Computer Engineering",
        languages={"Ukrainian", "English", "Polish", "German (a bit)"},
    )

Also, I have created fastapi-pagination package that helps you to paginate things (obviously) using FastAPI ๐Ÿ“–. Another thing that I currently work on is fastapi-filters package. Hope one day it will be useful for someone as fastapi-pagination is ๐Ÿธ.

Python related

I have several contributions to Python itself (commits). The most interesting one is (#23316 Store func annotations as a tuple). This optimization reduces memory footprint and improves performance of loading modules having many func annotations.

>>> sys.getsizeof({"a":"int","b":"int","return":"int"})
232
>>> sys.getsizeof(("a","int","b","int","return","int"))
88

The tuple is converted into dict on the fly when func.__annotations__ is accessed first.

PyCharm related

I have created a plugin (pycharm-evaluate-async-code) for PyCharm that helps you evaluate async code the using Evaluate Expression window. This is really useful when you are debugging your code and want to check some async stuff. I guess it's my favorite project that I have ever done (because I used it every day and it really saved me a lot of time).

evaluate_expression

pycharm-evaluate-async-code's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar uriyyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

wordhui

pycharm-evaluate-async-code's Issues

invalid syntax error

image

java.lang.Throwable: No connection (command:  113 )
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:159)
	at com.jetbrains.python.debugger.pydev.AbstractCommand.execute(AbstractCommand.java:159)
	at com.jetbrains.python.debugger.pydev.RemoteDebugger.evaluate(RemoteDebugger.java:158)
	at com.jetbrains.python.debugger.pydev.MultiProcessDebugger.evaluate(MultiProcessDebugger.java:167)
	at com.jetbrains.python.debugger.PyDebugProcess.evaluate(PyDebugProcess.java:752)
	at com.jetbrains.python.debugger.PyDebugProcess.evaluate(PyDebugProcess.java:748)
	at com.uriyyo.evaluate_async_code.AsyncPyDebugRunner$createDebugProcess$1.evaluate(AsyncPyDebugRunner.kt:40)
	at com.jetbrains.python.debugger.PyDebuggerEvaluator.lambda$doEvaluate$0(PyDebuggerEvaluator.java:59)
	at com.intellij.util.RunnableCallable.call(RunnableCallable.java:20)
	at com.intellij.util.RunnableCallable.call(RunnableCallable.java:11)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.call(ApplicationImpl.java:270)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
	at java.base/java.lang.Thread.run(Thread.java:834)

I'm using pyppeteer

Support event loops other than asyncio

I got an error message saying that uvloop isn't supported, and that it only supports programs running in asyncio. I was debugging a fastAPI service, so I believe making the plugin more extensible would be a valuable feature.

Doesn't work

RuntimeError: this event loop is already running.

not working when using fastapi

I'm really sorry, but due to my poor English, I can only use translation software.
image
When I started the FASTAPI service using the debugger method, the front-end sent the request successfully with a breakpoint, but still unable to execute asynchronous code

Don't work with docker-compose interpreter.

When start app using docker interpreter and stop in somebreakpoint there is SyntaxError "await outside function"

Project configuration:
image

Code for test:

import uvicorn
from fastapi import FastAPI

app = FastAPI()


@app.get("/test2/")
async def test_async():
    return {}


if __name__ == '__main__':
    uvicorn.run(app, port=5000, host='0.0.0.0')

Great plugin , but doesn't work anymore in pycharm 2021.3.1

Basically if you try and await in a console you get SyntaxError: 'await' outside function -

I use a virtual environment - used to work beautifully before upgrading pycharm . I am also on the latest version of the plugin 1.19.

if it helps. the stacktrace looks like this:-

import asyncio
await asyncio.sleep(1)

Traceback (most recent call last):
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/code.py", line 63, in runsource
    code = self.compile(source, filename, symbol)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 178, in __call__
    return _maybe_compile(self.compiler, source, filename, symbol)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 106, in _maybe_compile
    raise err1
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 93, in _maybe_compile
    code1 = compiler(source + "\n", filename, symbol)
  File "/usr/local/Cellar/[email protected]/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/codeop.py", line 143, in __call__
    codeob = compile(source, filename, symbol, self.flags, True)
  File "<input>", line 1
SyntaxError: 'await' outside function

DeprecationWarning: There is no current event loop

I'm getting this warning with Python 3.10 (didn't happen with Python 3.9):

C:\Users\xxx\AppData\Roaming\JetBrains\PyCharm2022.1\plugins\evaluate-async-code\_pydevd_async_debug.py C:\Users\xxx\software\JetBrains\PyCharm\plugins\python\helpers\pydev\pydevd.py --module --multiprocess --qt-support=auto --client 127.0.0.1 --port 51025 --file uvicorn main:app --port 19002 --log-level debug
C:\Users\xxx\AppData\Roaming\JetBrains\PyCharm2022.1\plugins\evaluate-async-code\_pydevd_async_debug.py:243: DeprecationWarning: There is no current event loop
  loop = asyncio.get_event_loop()
C:\Users\xxx\AppData\Roaming\JetBrains\PyCharm2022.1\plugins\evaluate-async-code\_pydevd_async_debug.py:12: DeprecationWarning: There is no current event loop
  loop = loop or asyncio.get_event_loop()
Connected to pydev debugger (build 221.5787.24)
C:\Users\xxx\AppData\Roaming\JetBrains\PyCharm2022.1\plugins\evaluate-async-code\_pydevd_async_debug.py:36: DeprecationWarning: There is no current event loop
  task = asyncio.ensure_future(main)

How does it works?

After install this plugin (IDE was restarted) in evaluate expression still getting error: SyntaxError: 'await' outside function.
Could you explain how it should work?

asyncio.create_subprocess_exec() will throw notImplementedError exception on Windows

Thanks for the excellent plugin

here is my code for the test

import asyncio


async def main():
    await asyncio.create_subprocess_exec('C:/Windows/System32/cmd.exe')


if __name__ == '__main__':
    asyncio.run(main())

traceback :

C:\Users\X\scoop\shims\python.exe C:\Users\X\AppData\Roaming\JetBrains\PyCharm2021.3\plugins\evaluate-async-code\_pydevd_async_debug.py "C:\Program Files\JetBrains\PyCharm 2021.3\plugins\python\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 52157 --file F:/projects/nftest/b.py
Connected to pydev debugger (build 213.6777.50)
Traceback (most recent call last):
  File "C:\Users\X\AppData\Roaming\JetBrains\PyCharm2021.3\plugins\evaluate-async-code\_pydevd_async_debug.py", line 38, in run
    return loop.run_until_complete(task)
  File "C:\Users\X\AppData\Roaming\JetBrains\PyCharm2021.3\plugins\evaluate-async-code\_pydevd_async_debug.py", line 81, in run_until_complete
    return f.result()
  File "C:\Users\X\scoop\apps\python39\current\lib\asyncio\futures.py", line 201, in result
    raise self._exception
  File "C:\Users\X\scoop\apps\python39\current\lib\asyncio\tasks.py", line 256, in __step
    result = coro.send(None)
  File "F:/projects/nftest/b.py", line 5, in main
    await asyncio.create_subprocess_exec('C:/Windows/System32/cmd.exe')
  File "C:\Users\X\scoop\apps\python39\current\lib\asyncio\subprocess.py", line 236, in create_subprocess_exec
    transport, protocol = await loop.subprocess_exec(
  File "C:\Users\X\scoop\apps\python39\current\lib\asyncio\base_events.py", line 1661, in subprocess_exec
    transport = await self._make_subprocess_transport(
  File "C:\Users\X\scoop\apps\python39\current\lib\asyncio\base_events.py", line 493, in _make_subprocess_transport
    raise NotImplementedError
NotImplementedError

Process finished with exit code 1

workaround:

import asyncio


async def main():
    await asyncio.create_subprocess_exec('C:/Windows/System32/cmd.exe')


if __name__ == '__main__':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
    asyncio.run(main())

Crashing in PyCharm debugger on Django tests

This started happening for me when running Django tests in PyCharm debugger, it crashes on various instances of sync_to_async.

  File "/Users/dev/.envs/pwn_backend_py_3_10/lib/python3.10/site-packages/asgiref/sync.py", line 220, in __call__
    loop_future.result()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/Users/dev/.envs/pwn_backend_py_3_10/lib/python3.10/site-packages/asgiref/sync.py", line 276, in _run_event_loop
    asyncio.set_event_loop(self.main_event_loop)
  File "/Users/dev/Library/Application Support/JetBrains/PyCharm2023.1/plugins/evaluate-async-code/_pydevd_async_debug.py", line 325, in set_loop_wrapper
    _patch_loop_if_not_patched(loop)
  File "/Users/dev/Library/Application Support/JetBrains/PyCharm2023.1/plugins/evaluate-async-code/_pydevd_async_debug.py", line 307, in _patch_loop_if_not_patched
    _patch_loop(loop)
  File "/Users/dev/Library/Application Support/JetBrains/PyCharm2023.1/plugins/evaluate-async-code/_pydevd_async_debug.py", line 175, in _patch_loop
    raise ValueError('Can\'t patch loop of type %s' % type(loop))
ValueError: Can't patch loop of type <class 'NoneType'>

ValueError when run on WSL2 Ubuntu, Pycharm

C:\Windows\system32\wsl.exe --distribution Ubuntu --exec /bin/sh -c "export ENV=dev" && cd /mnt/c/Users/n2/devs/codustry/gebwai/backend/app && /mnt/c/Users/n2/devs/codustry/gebwai/backend/.venv/bin/python '/mnt/c/Program Files/JetBrains/PyCharm 2020.3.3/plugins/python/helpers/pydev/pydevd.py' '/mnt/c/Program Files/JetBrains/PyCharm 2020.3.3/plugins/python/helpers/pydev/pydevd.py' --multiproc --qt-support=auto --client 172.24.64.1 --port 54991 --file /mnt/c/Users/n2/devs/codustry/gebwai/backend/app/main.py"
Traceback (most recent call last):
  File "/mnt/c/Program Files/JetBrains/PyCharm 2020.3.3/plugins/python/helpers/pydev/pydevd.py", line 1997, in main
    setup = process_command_line(sys.argv)
  File "/mnt/c/Program Files/JetBrains/PyCharm 2020.3.3/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_command_line_handling.py", line 146, in process_command_line
    raise ValueError("Unexpected option: " + argv[i])
ValueError: Unexpected option: /mnt/c/Program Files/JetBrains/PyCharm 2020.3.3/plugins/python/helpers/pydev/pydevd.py
Usage:
	pydevd.py --port N [(--client hostname) | --server] --file executable [file_options]

Event loop is already running error

When I call an awaitable in the debug console, I receive this message:

Traceback (most recent call last):
  File "/Users/cleancoder/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.5284.18/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/Users/cleancoder/Library/Application Support/JetBrains/Toolbox/apps/PyCharm-P/ch-0/212.5284.18/PyCharm.app.plugins/evaluate-async-code/_pydevd_async_debug.py", line 462, in async_eval
    exec(code_obj, _globals, _locals)
  File "<eval>", line 28, in <module>
  File "/Users/cleancoder/.pyenv/versions/3.8.7/lib/python3.8/asyncio/base_events.py", line 592, in run_until_complete
    self._check_running()
  File "/Users/cleancoder/.pyenv/versions/3.8.7/lib/python3.8/asyncio/base_events.py", line 552, in _check_running
    raise RuntimeError('This event loop is already running')
RuntimeError: This event loop is already running

Is there something I can do about it?

Fails the invocation of the latest IDEA EAP 6

Internal error. Please refer to https://jb.gg/ide/critical-startup-errors

com.intellij.diagnostic.PluginException: com.jetbrains.python.console.PythonConsoleRunnerFactory -> com.uriyyo.evaluate_async_code.AsyncPyDebugConsoleRunnerFactory [Plugin: com.uriyyo.evaluate_async_code]
    at com.intellij.serviceContainer.ComponentManagerImpl.registerServices(ComponentManagerImpl.kt:567)
    at com.intellij.serviceContainer.ComponentManagerImpl.registerComponents(ComponentManagerImpl.kt:328)
    at com.intellij.openapi.client.ClientAwareComponentManager.registerComponents(ClientAwareComponentManager.kt:58)
    at com.intellij.serviceContainer.ComponentManagerImpl.registerComponents$default(ComponentManagerImpl.kt:310)
    at com.intellij.platform.ide.bootstrap.ApplicationLoader$loadApp$2$initServiceContainerJob$1$1.invokeSuspend(ApplicationLoader.kt:95)
    at com.intellij.platform.ide.bootstrap.ApplicationLoader$loadApp$2$initServiceContainerJob$1$1.invoke(ApplicationLoader.kt)
    at com.intellij.platform.ide.bootstrap.ApplicationLoader$loadApp$2$initServiceContainerJob$1$1.invoke(ApplicationLoader.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at com.intellij.platform.diagnostic.telemetry.impl.TracerKt.span(tracer.kt:56)
    at com.intellij.platform.diagnostic.telemetry.impl.TracerKt.span$default(tracer.kt:49)
    at com.intellij.platform.ide.bootstrap.ApplicationLoader$loadApp$2$initServiceContainerJob$1.invokeSuspend(ApplicationLoader.kt:94)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.UndispatchedCoroutine.afterResume(CoroutineContext.kt:270)
    at kotlinx.coroutines.AbstractCoroutine.resumeWith(AbstractCoroutine.kt:102)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:46)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Caused by: com.intellij.platform.instanceContainer.InstanceNotRegisteredException: com.jetbrains.python.console.PythonConsoleRunnerFactory -> com.uriyyo.evaluate_async_code.AsyncPyDebugConsoleRunnerFactory
    at com.intellij.platform.instanceContainer.internal.InstanceRegistrarImpl.overrideInitializer(InstanceRegistrarImpl.kt:47)
    at com.intellij.serviceContainer.ComponentManagerImpl.registerServices2Inner(ComponentManagerImpl.kt:604)
    at com.intellij.serviceContainer.ComponentManagerImpl.registerServices(ComponentManagerImpl.kt:560)
    ... 21 more

-----
Your JRE: 17.0.10+8-b1207.1 amd64 (JetBrains s.r.o.)
C:\Users\o.kulychok\AppData\Local\Programs\IntelliJ IDEA Ultimate\jbr

DeprecationWarning: There is no current event loop

Similar to #52 (comment)

Python Version: 3.10.9
Evaluate Async Code Version: 1.22

......Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\223.8617.48.plugins\evaluate-async-code\_pydevd_async_debug.py:45: DeprecationWarning: There is no current event loop
loop = events.get_event_loop_policy().get_event_loop()

Any plan to support trio?

If you could point me in the right direction I might be able to implement this myself and add a PR.

Thanks in advance

Doesn't work with python 3.11.1

Hello, thank You for your product. It's very helpful.

Got an error on running Python Console with python3.11.1
In asyncio module, get_event_loop method, a 682 row of asyncio/events.py

  File "<string>", line 339, in <module>
  File "<string>", line 310, in patch_asyncio
  File "<string>", line 16, in apply
  File "<string>", line 45, in _get_event_loop
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/events.py", line 682, in get_event_loop
    if not (module == 'asyncio' or module.startswith('asyncio.')):
                                   ^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'startswith'

Just sent a crash log for your refer if you have time to check.

See crash log here sometime:
java.lang.NullPointerException: super.evaluate(expression, execute, doTrunc) must not be null
at com.uriyyo.evaluate_async_code.AsyncPyDebugProcess.evaluate(AsyncPyDebugProcess.kt:33)
at com.jetbrains.python.debugger.PyDebuggerEvaluator.lambda$doEvaluate$0(PyDebuggerEvaluator.java:59)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:246)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
at java.base/java.lang.Thread.run(Thread.java:833)

The plugin does not work in debug console

Hello,

In the plugin description, you wrote:

Finally, you can use async/await during debugging your code. Currently supports: evaluate an expression, conditional breakpoints, console window.

However, I'm trying to use your plugin in debug console but it does not work. I'm getting the errors.

Before evaluation in "Evaluate expression" window:

>>> await foo()
  File "<input>", line 1
SyntaxError: 'await' outside function

After evaluation in "Evaluate expression" window:

>>> await foo()
  File "<input>", line 1
    __import('sys')__.__async_eval__('await foo()\n', globals(), locals())
                   ^
SyntaxError: invalid syntax

My test code:

import asyncio

async def foo():
    print('hello')

async def main():
    await foo()   # <-- the breakpoint is here

if __name__ == '__main__':
    asyncio.run(main())

2020-12-21_11-28-29

I'm using Python 3.8/3.9 and PyCharm 2020.3, Evaluate async code 1.6

After installing this plug-in, running the following code in debug mode will report an error

After installing the plug-in, the following error will appear when running the following code in debug mode: --> attributeerror: 'playwrightcontextmanager' object has no attribute '_ playwright'

The complete code is as follows

from playwright.sync_api import sync_playwright

"""
The following code can run successfully, but after installing this plug-in, pycharm cannot run the following code in debug mode. Pycharm without this plug-in can run the following code successfully in debug mode
"""
playwright_context_manager = sync_playwright()
playwright = playwright_context_manager.start()  # Run in debug mode, there will be an error here
browser = playwright.chromium.launch(headless=False)
context = browser.new_context(ignore_https_errors=True)
page = context.new_page()
page.goto("http://playwright.dev")
print(page.title())
browser.close()

The complete error report is as follows

D:\App\Minconda\envs\py38\python.exe C:\Users\**\AppData\Roaming\JetBrains\PyCharm2020.3\plugins\evaluate-async-code\_pydevd_async_debug.py "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\pydevd.py" --multiproc --qt-support=auto --client 127.0.0.1 --port 64914 --file D:/workspace/BaoBao/playwright_t.py
Connected to pydev debugger (build 203.7717.81)

Traceback (most recent call last):
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\pydevd.py", line 1477, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/workspace/BaoBao/playwright_t.py", line 4, in <module>
    playwright = playwright_context_manager.start()
  File "D:\App\Minconda\envs\py38\lib\site-packages\playwright\sync_api\_context_manager.py", line 75, in start
    return self.__enter__()
  File "D:\App\Minconda\envs\py38\lib\site-packages\playwright\sync_api\_context_manager.py", line 70, in __enter__
    playwright = self._playwright
AttributeError: 'PlaywrightContextManager' object has no attribute '_playwright'
Traceback (most recent call last):
  File "C:\Users\hui\AppData\Roaming\JetBrains\PyCharm2020.3\plugins\evaluate-async-code\_pydevd_async_debug.py", line 458, in <module>
    run_path(sys.argv.pop(1), {}, "__main__")
  File "D:\App\Minconda\envs\py38\lib\runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "D:\App\Minconda\envs\py38\lib\runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "D:\App\Minconda\envs\py38\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\pydevd.py", line 2167, in <module>
    main()
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\pydevd.py", line 2158, in main
    globals = debugger.run(setup['file'], None, None, is_module)
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\pydevd.py", line 1470, in run
    return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\pydevd.py", line 1477, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "D:\App\PyCharm 2020.3.5\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "D:/workspace/BaoBao/playwright_t.py", line 4, in <module>
    playwright = playwright_context_manager.start()
  File "D:\App\Minconda\envs\py38\lib\site-packages\playwright\sync_api\_context_manager.py", line 75, in start
    return self.__enter__()
  File "D:\App\Minconda\envs\py38\lib\site-packages\playwright\sync_api\_context_manager.py", line 70, in __enter__
    playwright = self._playwright
AttributeError: 'PlaywrightContextManager' object has no attribute '_playwright'

Full code screenshot

image

Complete error report screenshot

image

pycharm version

PyCharm 2020.3.5 (Professional Edition)
Build #PY-203.7717.81, built on March 25, 2021
Expiration date: June 26, 2021
Runtime version: 11.0.10+8-b1145.96 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
GC: ParNew, ConcurrentMarkSweep
Memory: 980M
Cores: 16

Plug-in version

image

The plugin is not being applied automatically

The plugin does not work in debug console (issue: await outside function) automatically. To make it work one has to click "evaluate expression" and put some await ... as the expression. After that action, the await in the console works OK (i.e. there is no await outside function).


Plugin version: 1.2.0
PyCharm version: 2022.2.3 (Build #PY-222.4345.23, built on October 10, 2022)

Add unit tests

I must add unit tests to cover most of the async code evaluation cases

awaiting a function crashes the debugger

As soon as I set a breakpoint and evaluate e.g. await asyncio.sleep(1), I get the following error log and from then on stepping does not work anymore.

Exception in callback Task.task_wakeup(<Future finished result=None>)
handle: <Handle Task.task_wakeup(<Future finished result=None>)>
Traceback (most recent call last):
  File "C:\Users\Administrator\.pyenv\pyenv-win\versions\3.10.7\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
RuntimeError: Cannot enter into task <Task pending name='Task-1' coro=<BrowserWorker.start_loop() running at C:\Users\Administrator\PycharmProjects\project\project\work\service.py:125> wait_for=<Future finished result=None> cb=[_run_until_complete_cb() at C:\Users\Administrator\.pyenv\pyenv-win\versions\3.10.7\lib\asyncio\base_events.py:184]> while another task <Task pending name='Task-3' coro=<SolverJob.get_token() running at C:\Users\Administrator\PycharmProjects\project\project\work\service.py:85>> is being executed.
Exception in callback Task.task_wakeup(<Future finished result=None>)
handle: <Handle Task.task_wakeup(<Future finished result=None>)>
Traceback (most recent call last):
  File "C:\Users\Administrator\.pyenv\pyenv-win\versions\3.10.7\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
RuntimeError: Cannot enter into task <Task pending name='Task-2' coro=<BrowserWorker.watch_for_completed_jobs() running at C:\Users\Administrator\PycharmProjects\project\project\work\service.py:174> wait_for=<Future finished result=None>> while another task <Task pending name='Task-3' coro=<SolverJob.get_token() running at C:\Users\Administrator\PycharmProjects\project\project\work\service.py:85>> is being executed.
Exception in callback Task.task_wakeup(<Future finished result=None>)
handle: <Handle Task.task_wakeup(<Future finished result=None>)>
Traceback (most recent call last):
  File "C:\Users\Administrator\.pyenv\pyenv-win\versions\3.10.7\lib\asyncio\events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
RuntimeError: Cannot enter into task <Task pending name='Task-6' coro=<Connection.run() running at C:\Users\Administrator\PycharmProjects\project\venv\lib\site-packages\playwright\_impl\_connection.py:226> wait_for=<Future finished result=None>> while another task <Task pending name='Task-3' coro=<SolverJob.get_token() running at C:\Users\Administrator\PycharmProjects\project\project\work\service.py:85>> is being executed.
attempts
Task was destroyed but it is pending!
task: <Task pending name='Task-2' coro=<BrowserWorker.watch_for_completed_jobs() running at C:\Users\Administrator\PycharmProjects\project\project\work\service.py:174> wait_for=<Future finished result=None>>
Task was destroyed but it is pending!
task: <Task pending name='Task-6' coro=<Connection.run() running at C:\Users\Administrator\PycharmProjects\project\venv\lib\site-packages\playwright\_impl\_connection.py:226> wait_for=<Future finished result=None>>
Python 3.10.7 (tags/v3.10.7:6cc6b13, Sep  5 2022, 14:08:36) [MSC v.1933 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.5.0 -- An enhanced Interactive Python. Type '?' for help.
PyDev console: using IPython 8.5.0
Out[1]: 0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.