Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

How to run python3 code in multiple windows

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:
------for line in process:
------------if milliseconds > 1000 or no_milliseconds_shown:
-----------------wait main program
------------else:
----------------pass



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
(Aug 24, 2020 10:45 AM)0u1law Wrote:  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:
------for line in process:
------------if milliseconds > 1000 or no_milliseconds_shown:
-----------------wait main program
------------else:
----------------pass



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



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
(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

usually to do web scraping I use Beautiful Soup

but i want it that way.
(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

usually to do web scraping I use Beautiful Soup

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?
[Image: VgXWA2P.png]
(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.
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?
"Give a Man a Fish, and You Feed Him for a Day. Teach a Man To Fish, and You Feed Him for a Lifetime"
https://docs.python.org/3/library/multiprocessing.html
+ search for examples on GitHub.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by john ronaldsadJul 20, 2022 06:49 PM 4 231 Jul 20, 2022 06:49 PM
Last Post: john ronaldsad
[Python] by MaskinMay 25, 2022 05:29 PM 4 371 May 25, 2022 05:29 PM
Last Post: Maskin
[Shell] by Emre_Jan 12, 2021 11:16 PM 0 137 Jan 12, 2021 11:16 PM
Last Post: Emre_