0

I use MSS for Python for capturing screenshots rapidly on my computer, but when putting the image capturing inside a while loop:

import mss
while True:
    sct = mss.mss()

I get an error message Maximum number of clients reachedSegmentation fault (core dumped). How do I solve this?

Tiger-222
  • 6,677
  • 3
  • 47
  • 60
Andreas Forslöw
  • 2,220
  • 23
  • 32

2 Answers2

1

You should use the context manager:

import mss

with mss.mss() as sct:
    while True:
        # ...
Tiger-222
  • 6,677
  • 3
  • 47
  • 60
0

The solution is simple, and I think it has to do with not closing the mss feed properly. Simply add an sct.close() at the end of each iteration:

import mss
while True:
    sct = mss.mss()
    sct.close()
Andreas Forslöw
  • 2,220
  • 23
  • 32