![]() |
|
[Python] How to run python3 code in multiple windows - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] How to run python3 code in multiple windows (/showthread.php?tid=6104943) |
How to run python3 code in multiple windows - 0u1law - Aug 24, 2020 hey guys i want to write a programm which can do multiple tasks at once with multiprocessing/asyncio. but i dont know how to give the output of the code in 2 or 3 cmds just for organizing and clear overview. my intention is to download some images from specific website over a long period of time. the output for every downloaded picture is like "pic1.jpg done" "pic2.jpg done" and so on. and at the other side i want to check the internet connection permanently so if the connection gets interrupted i can stop my main program and wait until the connection ist established again! which modules do i need for that kind of intention ? and just by the way im tying to use the ping command with python like this : Code process = subprocess.Popen("ping -t www.google.com")how can i read the output and check every single time the pingtime? something like this PSEUDOCODE Code while True:if there are other ways(im sure there is) which is more efficient or a better solution for a newbie please tell me. thanks a lot 0u1law RE: How to run python3 code in multiple windows - Argonaut.exe - Aug 24, 2020 (Aug 24, 2020 10:45 AM)0u1law Wrote: hey guys a try catch in while loop isn't enough? if somehow you need to be a little bit optimized you can add a wait in the catch. I mean if the site is unreachable you will get some error or a different answer just parse it without pinging and throw yourself the exception usually to do web scraping I use Beautiful Soup RE: How to run python3 code in multiple windows - 0u1law - Aug 24, 2020 (Aug 24, 2020 12:14 PM)Argonaut.exe Wrote: a try catch in while loop isn't enough? if somehow you need to be a little bit optimized you can add a wait in the catch. I mean if the site is unreachable you will get someerror or a different answer just parse it without pinging and throw yourself the exception but i want it that way. RE: How to run python3 code in multiple windows - Oscura - Aug 25, 2020 (Aug 24, 2020 12:14 PM)Argonaut.exe Wrote: a try catch in while loop isn't enough? if somehow you need to be a little bit optimized you can add a wait in the catch. I mean if the site is unreachable you will get someerror or a different answer just parse it without pinging and throw yourself the exception I second this. Python libraries such as requests will throw an exception if no internet connection is available. Catch this and possibly do something with it. To optimize you could add a sleep of a minute or so in the loop as Argonaut suggested. Do you have a specific reason to want it otherwise? RE: How to run python3 code in multiple windows - 0u1law - Aug 26, 2020 (Aug 25, 2020 03:23 PM)Oscura Wrote: I second this. Python libraries such as requests will throw an exception if no internet connection is available. Catch this and possibly do something with it. To optimize you could add a sleep of a minute or so in the loop as Argonaut suggested. Do you have a specific reason to want it otherwise? there are some reasons why i want to know how, as first me as a advanced beginner it is a good way to watch the programs progress, but seperatly for every work that have to be done. and for me it will be important that i can cancel one task without influence other tasks or influence just the "connected" tasks. getting control of this. or starting my own program which automates some stuff and i want to check it out but seperatly and/or every time i need. i hope you understand me despite my bad english. RE: How to run python3 code in multiple windows - Harley Quinn - Aug 28, 2020 I don't understand why you would want to have this running on two separate programs. You will need to handle the exception that requests throws anyway. Happy to help you build something robust, share some code we can have a look? RE: How to run python3 code in multiple windows - Pernat1y - Aug 28, 2020 https://docs.python.org/3/library/multiprocessing.html + search for examples on GitHub. |