Python traceback for coroutineHow can I represent an 'Enum' in Python?Way to create multiline comments in Python?What is the Python 3 equivalent of “python -m SimpleHTTPServer”How to catch exceptions in async / await based single-threaded coroutine implementationAsync/await as a replacement of coroutinesWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Python native coroutines and send()How to inspect program state in the presence of generators/coroutines?C++1z coroutine threading context and coroutine schedulingCan a Python coroutine be implemented without await or yield?

Can I still be respawned if I die by falling off the map?

What is Cash Advance APR?

Is this toilet slogan correct usage of the English language?

What should you do if you miss a job interview (deliberately)?

Can a Canadian Travel to the USA twice, less than 180 days each time?

Why does a simple loop result in ASYNC_NETWORK_IO waits?

How to hide some fields of struct in C?

PTIJ: Haman's bad computer

Is there a way to get `mathscr' with lower case letters in pdfLaTeX?

Why is the "ls" command showing permissions of files in a FAT32 partition?

Can a stoichiometric mixture of oxygen and methane exist as a liquid at standard pressure and some (low) temperature?

Is there a RAID 0 Equivalent for RAM?

Picking the different solutions to the time independent Schrodinger eqaution

What happens if you are holding an Iron Flask with a demon inside and walk into an Antimagic Field?

Is aluminum electrical wire used on aircraft?

Can the US President recognize Israel’s sovereignty over the Golan Heights for the USA or does that need an act of Congress?

What are some good ways to treat frozen vegetables such that they behave like fresh vegetables when stir frying them?

What is the English pronunciation of "pain au chocolat"?

How do apertures which seem too large to physically fit work?

What is the highest possible scrabble score for placing a single tile

On a tidally locked planet, would time be quantized?

Why would a new[] expression ever invoke a destructor?

What does chmod -u do?

What features enable the Su-25 Frogfoot to operate with such a wide variety of fuels?



Python traceback for coroutine


How can I represent an 'Enum' in Python?Way to create multiline comments in Python?What is the Python 3 equivalent of “python -m SimpleHTTPServer”How to catch exceptions in async / await based single-threaded coroutine implementationAsync/await as a replacement of coroutinesWhy is “1000000000000000 in range(1000000000000001)” so fast in Python 3?Python native coroutines and send()How to inspect program state in the presence of generators/coroutines?C++1z coroutine threading context and coroutine schedulingCan a Python coroutine be implemented without await or yield?













1















Let's say I have the following code:



from types import coroutine

@coroutine
def stop():
yield 1

async def test2():
await stop()

async def test1():
await test2()
await test2() # Here
await test2()

coro = test1()
coro.send(None)
coro.send(None)


How can I get traceback (traceback object) for current coroutine state, i.e. line marked with comment, without artificially throwing unneeded exception?










share|improve this question


























    1















    Let's say I have the following code:



    from types import coroutine

    @coroutine
    def stop():
    yield 1

    async def test2():
    await stop()

    async def test1():
    await test2()
    await test2() # Here
    await test2()

    coro = test1()
    coro.send(None)
    coro.send(None)


    How can I get traceback (traceback object) for current coroutine state, i.e. line marked with comment, without artificially throwing unneeded exception?










    share|improve this question
























      1












      1








      1








      Let's say I have the following code:



      from types import coroutine

      @coroutine
      def stop():
      yield 1

      async def test2():
      await stop()

      async def test1():
      await test2()
      await test2() # Here
      await test2()

      coro = test1()
      coro.send(None)
      coro.send(None)


      How can I get traceback (traceback object) for current coroutine state, i.e. line marked with comment, without artificially throwing unneeded exception?










      share|improve this question














      Let's say I have the following code:



      from types import coroutine

      @coroutine
      def stop():
      yield 1

      async def test2():
      await stop()

      async def test1():
      await test2()
      await test2() # Here
      await test2()

      coro = test1()
      coro.send(None)
      coro.send(None)


      How can I get traceback (traceback object) for current coroutine state, i.e. line marked with comment, without artificially throwing unneeded exception?







      python-3.x python-asyncio coroutine






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked yesterday









      adontzadontz

      8681029




      8681029






















          1 Answer
          1






          active

          oldest

          votes


















          0














          Use of traceback.print_stack() will give you the exact same traceback as thrown exception:



          async def test1():
          await test2()

          traceback.print_stack()
          # raise Exception()

          await test2() # Here
          await test2()


          You can use traceback.extract_stack() if you want to recieve object instead of printing.




          Note however that you're doing something strange. asyncio coroutines is not supposed to be run use it's generator's nature functions like .send().



          In asyncio you await for coroutines and run top level coroutine using event loop. Please see how it's done in documentation.



          I write another small example that shows how to print start inside inner coroutine when you use asyncio regular way:



          import asyncio
          import traceback


          async def test3():
          traceback.print_stack()


          async def test2():
          await test3()


          async def test1():
          await test2()


          asyncio.run(test1())


          You'll see:



           File "C:main.py", line 24, in <module>
          asyncio.run(test1())

          # inner event loop stack here

          File "C:main.py", line 21, in test1
          await test2()
          File "C:main.py", line 17, in test2
          await test3()
          File "C:main.py", line 13, in test3
          traceback.print_stack()





          share|improve this answer






















            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280869%2fpython-traceback-for-coroutine%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Use of traceback.print_stack() will give you the exact same traceback as thrown exception:



            async def test1():
            await test2()

            traceback.print_stack()
            # raise Exception()

            await test2() # Here
            await test2()


            You can use traceback.extract_stack() if you want to recieve object instead of printing.




            Note however that you're doing something strange. asyncio coroutines is not supposed to be run use it's generator's nature functions like .send().



            In asyncio you await for coroutines and run top level coroutine using event loop. Please see how it's done in documentation.



            I write another small example that shows how to print start inside inner coroutine when you use asyncio regular way:



            import asyncio
            import traceback


            async def test3():
            traceback.print_stack()


            async def test2():
            await test3()


            async def test1():
            await test2()


            asyncio.run(test1())


            You'll see:



             File "C:main.py", line 24, in <module>
            asyncio.run(test1())

            # inner event loop stack here

            File "C:main.py", line 21, in test1
            await test2()
            File "C:main.py", line 17, in test2
            await test3()
            File "C:main.py", line 13, in test3
            traceback.print_stack()





            share|improve this answer



























              0














              Use of traceback.print_stack() will give you the exact same traceback as thrown exception:



              async def test1():
              await test2()

              traceback.print_stack()
              # raise Exception()

              await test2() # Here
              await test2()


              You can use traceback.extract_stack() if you want to recieve object instead of printing.




              Note however that you're doing something strange. asyncio coroutines is not supposed to be run use it's generator's nature functions like .send().



              In asyncio you await for coroutines and run top level coroutine using event loop. Please see how it's done in documentation.



              I write another small example that shows how to print start inside inner coroutine when you use asyncio regular way:



              import asyncio
              import traceback


              async def test3():
              traceback.print_stack()


              async def test2():
              await test3()


              async def test1():
              await test2()


              asyncio.run(test1())


              You'll see:



               File "C:main.py", line 24, in <module>
              asyncio.run(test1())

              # inner event loop stack here

              File "C:main.py", line 21, in test1
              await test2()
              File "C:main.py", line 17, in test2
              await test3()
              File "C:main.py", line 13, in test3
              traceback.print_stack()





              share|improve this answer

























                0












                0








                0







                Use of traceback.print_stack() will give you the exact same traceback as thrown exception:



                async def test1():
                await test2()

                traceback.print_stack()
                # raise Exception()

                await test2() # Here
                await test2()


                You can use traceback.extract_stack() if you want to recieve object instead of printing.




                Note however that you're doing something strange. asyncio coroutines is not supposed to be run use it's generator's nature functions like .send().



                In asyncio you await for coroutines and run top level coroutine using event loop. Please see how it's done in documentation.



                I write another small example that shows how to print start inside inner coroutine when you use asyncio regular way:



                import asyncio
                import traceback


                async def test3():
                traceback.print_stack()


                async def test2():
                await test3()


                async def test1():
                await test2()


                asyncio.run(test1())


                You'll see:



                 File "C:main.py", line 24, in <module>
                asyncio.run(test1())

                # inner event loop stack here

                File "C:main.py", line 21, in test1
                await test2()
                File "C:main.py", line 17, in test2
                await test3()
                File "C:main.py", line 13, in test3
                traceback.print_stack()





                share|improve this answer













                Use of traceback.print_stack() will give you the exact same traceback as thrown exception:



                async def test1():
                await test2()

                traceback.print_stack()
                # raise Exception()

                await test2() # Here
                await test2()


                You can use traceback.extract_stack() if you want to recieve object instead of printing.




                Note however that you're doing something strange. asyncio coroutines is not supposed to be run use it's generator's nature functions like .send().



                In asyncio you await for coroutines and run top level coroutine using event loop. Please see how it's done in documentation.



                I write another small example that shows how to print start inside inner coroutine when you use asyncio regular way:



                import asyncio
                import traceback


                async def test3():
                traceback.print_stack()


                async def test2():
                await test3()


                async def test1():
                await test2()


                asyncio.run(test1())


                You'll see:



                 File "C:main.py", line 24, in <module>
                asyncio.run(test1())

                # inner event loop stack here

                File "C:main.py", line 21, in test1
                await test2()
                File "C:main.py", line 17, in test2
                await test3()
                File "C:main.py", line 13, in test3
                traceback.print_stack()






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 16 hours ago









                Mikhail GerasimovMikhail Gerasimov

                14.6k44071




                14.6k44071





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280869%2fpython-traceback-for-coroutine%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현