0

I have a website with the server app (app.js) programmed on nodejs. When a user makes a request, app.js spawns a child process. The child process is a python file which opens a selenium webdriver window, scrapes info with selenium, and then closes the browser.

When the user closes his/her browser, the python file keeps running and the selenium window remains open. If my user base increases, I will have a lot of unused, open selenium windows in my server. How can I avoid this?

I need a way to make app.js close a specific python child process and a specific selenium window when a user is disconnected, but let the other python processes and selenium windows keep running.

BTW, it's not a problem to tell when a user disconnects - I am using socket.on('disconnect') and this works well.

Nickolay
  • 31,095
  • 13
  • 107
  • 185
Felipe
  • 15
  • 2
  • Why does the python process not quit after scraping? Or if it does, why do you care about the user disconnecting during the scraping? For the specific question you have it would help to see the runnable example that demonstrates how you run the child process and what stops you from [killing the child process](https://stackoverflow.com/a/20189473/1026) in response to the disconnect. – Nickolay Aug 23 '19 at 16:53
  • Thanks for your answer! The python process does quit after scraping and the selenium chrome window does close after scraping. However, when the user disconnects, the python process keeps running and the selenium chrome window remains open. I want to stop the python process because it writes and reads temp files, so if the user disconnects and opens another session, there are two process accessing the same file names but the files could/should have different information. I want to stop the selenium chrome windows to avoid clogging the server with inactive processes. Thanks! – Felipe Aug 25 '19 at 17:18
  • The user can make two requests in parallel even without aborting the first one... You seem to have missed the second part of my comment; and I don't see how to help you without that information. – Nickolay Aug 26 '19 at 13:59
  • 1
    No worries, I'm all set - I realized I don't need to identify the chrome window. I just send a signal to that process to quit the browser. Thanks anyway! – Felipe Aug 27 '19 at 16:52

0 Answers0