Giter Club home page Giter Club logo

Comments (6)

dchiang avatar dchiang commented on August 17, 2024 1

@Sebadst you can do:

from pyvirtualdisplay import Display

display = Display()
display.start()
display.stop()
del display
display = Display()
display.start()

When calling display.stop() it in fact stops the Xvfb, Xephir or Xvnc displays but the Display object still exists. If I get rid of it and instantiate it again I am able to start the display again.

from pyvirtualdisplay.

ponty avatar ponty commented on August 17, 2024 1

You don't even have to delete the old object

>>> from pyvirtualdisplay import Display
>>> display = Display()
>>> display.start()
<pyvirtualdisplay.display.Display object at 0x7f0b585e9df0>
>>> display.stop()
<pyvirtualdisplay.display.Display object at 0x7f0b585e9df0>
>>> display = Display()
>>> display.start()
<pyvirtualdisplay.display.Display object at 0x7f0b5868b1f0>

You don't have such problems with context manager (check the README)

from pyvirtualdisplay import Display
with Display() as disp:
    # display is active
    pass
# display is stopped

from pyvirtualdisplay.

ponty avatar ponty commented on August 17, 2024

Display wraps one call to Xvfb, so you can use start() only once on it. Don't call it twice.

from pyvirtualdisplay import Display

display = Display()
display.start()
display.stop()

from pyvirtualdisplay.

Sebadst avatar Sebadst commented on August 17, 2024

what does the stop() call do exactly then?

from pyvirtualdisplay.

ponty avatar ponty commented on August 17, 2024

start() starts Xvfb stop() stops Xvfb.

Example from README:

from pyvirtualdisplay import Display
disp = Display().start()
# display is active
disp.stop()
# display is stopped

from pyvirtualdisplay.

dchiang avatar dchiang commented on August 17, 2024

Yes, working with context manager is an alternative but in my case I had a multi-threaded scenario with the virtual display as a shared resource where using context wouldn't allow me to implement the flexibility I needed and so I ended up just deleting the old object after stopping the display to be able to start it again when required.

from pyvirtualdisplay.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.