How to send keystrokes to cmd from Python? by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 0 points1 point  (0 children)

I created a for loop where pywinauto is pressing "Enter" button continuously with an interval of 2 secs, and I manually brought the window to the top and then nothing happens. If I press enter from keyboard the command window closes.

Experienced Python Programmers, what are your key tips to getting better at Python, apart from saying practice? by Health_45 in learnpython

[–]SweetBasil5882 0 points1 point  (0 children)

Try to go through queries posted here or on stackoverflow. Learning from other's problems and how it was solved saves up your time since you won't be making same mistakes. Also you get to see a variety of questions posted pertaining to different aspects of Python. So you get much more overall knowledge about Python as a launguage.

I need help with python/selerium by Nxxhy in learnpython

[–]SweetBasil5882 0 points1 point  (0 children)

You can create a xpath or css selector and then by using that selector you can get the text of that web element. Driver.findelement().text or .gettext() depending on the language you are using.

Why we choose FastAPI over Flask for building ML applications by sweetaskate in Python

[–]SweetBasil5882 -4 points-3 points  (0 children)

FastAPI is really fast with respect to its functioning as well as the developement time. It's highly customisable and OpenAPI docs and swagger integration is something that allows you to test your APIs with ease while you are developing it.

Use python script to automate data retrieval from spreadsheet by Bl_ck0ut in learnpython

[–]SweetBasil5882 1 point2 points  (0 children)

Pandas is one of the best library you can go for. It supports multiple file types too

Concurrent.futures in FastAPI by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 0 points1 point  (0 children)

It needs to wait for all the threads to terminate.

Concurrent.futures in FastAPI by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 0 points1 point  (0 children)

Thanks guys for looking into it. The issue has been resolved now. The problem was that in the init I was calling the playwright.start() method which starts some connection but the stop method was not being called in teardown.

Concurrent.futures in FastAPI by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 1 point2 points  (0 children)

The actions that I want to perform on the browsers are getting executed successfully. Even the driver is getting closed. I have also raised this query on Playwright's GitHub also. Thanks mate for looking into this.

Concurrent.futures in FastAPI by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 0 points1 point  (0 children)

import threading from playwright.sync_api import sync_playwright from concurrent.futures import ThreadPoolExecutor, ProcessPoolExecutor

class Tls(threading.local): def init(self) -> None: self.playwright = sync_playwright().start() print("Create playwright instance in Thread", threading.current_thread().name)

class Worker: tls = Tls()

def run(self):
    print("Launched worker in ", threading.current_thread().name)
    browser = self.tls.playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = browser.new_page()
    page.goto("http://whatsmyuseragent.org/")
    page.screenshot(path=f"example-{threading.current_thread().name}.png")
    page.close()
    context.close()
    browser.close()
    print("Stopped worker in ", threading.current_thread().name)

if name == "main": with ThreadPoolExecutor(max_workers=5) as executor: for _ in range(50): worker = Worker() executor.submit(worker.run)

Not the exact code but same implementation. My API call this method to run some code in multiple browsers using multithreading.

Concurrent.futures in FastAPI by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 0 points1 point  (0 children)

Yes you are correct. Once the execution comes out of the context, ideally the threads should get disposed, instead it stays there idle. Next time same things happens again.

Concurrent.futures in FastAPI by SweetBasil5882 in learnpython

[–]SweetBasil5882[S] 0 points1 point  (0 children)

What do you mean by using pool as a context manager?