#๐Ÿ”’ Loop not ending even though condition has been met.

74 messages ยท Page 1 of 1 (latest)

wispy bolt
#

I have this code function

clear dragonBOT
#

@wispy bolt

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

wispy bolt
#

this part of my function since it doesn't let me send

spice sorrel
#

!code

clear dragonBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

spice sorrel
#

!paste

clear dragonBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

wispy bolt
#

yeah basically

#

even though the condition is met

#

here's the log : 2024-08-11T19:51:31.140Z INFO Launching Playwright... 2024-08-11T19:51:35.281Z INFO Webdriver is scrolling... 2024-08-11T19:51:41.376Z INFO Webdriver is scrolling... 2024-08-11T19:52:16.668Z INFO Webdriver is scrolling... 2024-08-11T19:52:52.783Z INFO Webdriver is scrolling... 2024-08-11T19:53:15.676Z Scrolled to the bottom 2024-08-11T19:53:15.809Z Exiting loop and closing browser. 2024-08-11T19:53:23.980Z INFO Webdriver is scrolling... 2024-08-11T19:53:31.850Z INFO Webdriver is scrolling... 2024-08-11T19:54:06.219Z INFO Webdriver is scrolling... 2024-08-11T19:54:43.252Z INFO Webdriver is scrolling... 2024-08-11T19:55:07.196Z Scrolled to the bottom 2024-08-11T19:55:07.311Z Exiting loop and closing browser. it doesn't exit the loop

verbal dune
#

first of all, what you describe is not what happens, which means something isn't right about your observation

#
                                    print('Exiting loop and closing browser.')
                                    await browser.close()
                                    return data_list

if you ran that print, then you also either crashed, or ran that return, or entered some other loop in browser.close

#

more likely, you begin the loop multiple times - ie there's another loop around this

wispy bolt
#

I'm not sure to understand

#

there's not really another loop and the function is called one time

verbal dune
#

it isn't possible to stay in the function after those 3 lines, so that can't be what happens

wispy bolt
#

yes

#

but it still stays

#

I'm very confused because it should be exiting

verbal dune
#

you can easily confirm this by adding a print at the top of the function to see if it is called more than once

wispy bolt
#

I'll try

hasty parcel
#

The only explanation I can see besides the function exiting and being called again is if the function was called multiple times at the start and is interleaving between calls every time an await is reached.

spice sorrel
#

i saw u last time u sure u cant press 'end'? would remove the need for the whole loop.
also where do u assume it doesnt quit the loop?

wispy bolt
#

because of the logs

#

and that the function is called one time

spice sorrel
spice sorrel
#

oh sorry i only read the end and didnt see the exit message being there twice

wispy bolt
# verbal dune you can easily confirm this by adding a print at the top of the function to see ...
2024-08-11T20:10:42.771Z Fonction is called
2024-08-11T20:10:45.393Z INFO  Webdriver is scrolling...
2024-08-11T20:10:50.907Z INFO  Webdriver is scrolling...
2024-08-11T20:11:12.509Z Scrolled to the bottom
2024-08-11T20:11:12.512Z Exiting loop and closing browser.
2024-08-11T20:11:12.900Z Fonction is called
2024-08-11T20:11:17.828Z INFO  Webdriver is scrolling...
2024-08-11T20:11:24.683Z INFO  Webdriver is scrolling...
2024-08-11T20:11:46.615Z Scrolled to the bottom
2024-08-11T20:11:46.619Z Exiting loop and closing browser.```
#

you were right

#

function is called multiple time

#

but I called it only one time

#
 try:
            data = await get_full_html_content(keyword)
        except:
            try:
                error_traceback = traceback.format_exc()
                r.post('', json={'content': error_traceback})   
            except Exception as e:
                r.post('', json={'content': 'couldnt get error {e}'})  
        
        settings['ITEM_PIPELINES'] = { ActorDatasetPushPipeline: 1 }
        settings['TWISTED_REACTOR'] = 'twisted.internet.asyncioreactor.AsyncioSelectorReactor'
        settings['DEPTH_LIMIT'] = depth
        settings['RETRY_ENABLED'] = False
        settings['DOWNLOAD_TIMEOUT'] = 2.5
        
        data = await get_full_html_content(keyword)
        if data != 'No result':
            process = CrawlerProcess(settings)
            process.crawl(
            EmailScraper,  pattern_list=pattern_list, 
            crawling_depth = depth, data_dict=data, get_insta_details=insta_details)
            process.start()```
#

the rest of the code

#

the function is only called one time

spice sorrel
#

u use selenium right?

wispy bolt
#

NO

#

it's called twice

#

I'm dumb

#

I just noticed it

#

bruhhh

#

I coded for like 5-6 hours straight

#

that's why I think

#

I feel so dumb right now

spice sorrel
#

its keyboardEvent.End there according to this

wispy bolt
#

I'm ending it

#

by exiting the function

spice sorrel
#

also pageup/down is way faster than up and down

wispy bolt
#

it wil lget buggy

#

and don't charge the element I need to charge

#

so that's why I need it to be a little bit slow

spice sorrel
#

oh ok than end is also not ur key here

wispy bolt
#

but the key ends when the function is exited

#

so it's useless to try end it before exiting

spice sorrel
# wispy bolt I'm ending it

no its the end key it will go to the end of the line or the bottom of the site depending on where u use it

wispy bolt
#

ahhh

spice sorrel
wispy bolt
#

so no need to check if a trigger is there

#

?

spice sorrel
#

but if going too fast doesnt load stuff

#

than tis wont load any

wispy bolt
#

I'll try that tomorrow to see if it works

#

if it does

#

it will be really helpful

#

ty @spice sorrel

#

!close

clear dragonBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.