exit

Terminate all running threads at specific time

Terminate all running threads at specific time Question: i made a downloader based on a scheduler. So I wanted to download files at starting at a time of and stop before 6 am. I managed to achieve this using apscheduler that starts at 12 am, but i am not sure how to terminate all the …

Total answers: 1

Check if the browser opened with Selenium is still running (Python)

Check if the browser opened with Selenium is still running (Python) Question: I want to check if a browser opened with Selenium is still open. I would need this check for closing a program. If the browser is not open, then the GUI should be destroyed without a message (tk.messagebox) coming. But if the browser …

Total answers: 2

Exiting Python Debugger ipdb

Exiting Python Debugger ipdb Question: I use ipdb fairly often in a way to just jump to a piece of code that is isolated i.e. it is hard to write a real script that uses it. Instead I write a minimal test case with mocking and jump into it. Exemplary for the workflow: def func(): …

Total answers: 6

python sys.exit not working in try

python sys.exit not working in try Question: Python 2.7.5 (default, Feb 26 2014, 13:43:17) [GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2 Type “help”, “copyright”, “credits” or “license” for more information. >>> import sys >>> try: … sys.exit() … except: … print “in except” … in except >>> try: … sys.exit(0) … except: … print …

Total answers: 2

How do __enter__ and __exit__ work in Python decorator classes?

How do __enter__ and __exit__ work in Python decorator classes? Question: I’m trying to create a decorator class that counts how many times a function is called, but I’m getting an error message that says: “TypeError: __exit__() takes exactly 1 argument (4 given)” and I really don’t know how I’m giving it four arguments. My …

Total answers: 2

Exit a program conditional on input (Python 2)

Exit a program conditional on input (Python 2) Question: This is for a game. The game asks the user if s/he would like to play again. If not, the program should just exit. If yes, the entire game is repeated and asks to play again, and so on. while True: print “*game being played*” # …

Total answers: 4

Difference between exit() and sys.exit() in Python

Difference between exit() and sys.exit() in Python Question: In Python, there are two similarly-named functions, exit() and sys.exit(). What’s the difference and when should I use one over the other? Asked By: Drake Guan || Source Answers: exit is a helper for the interactive shell – sys.exit is intended for use in programs. The site …

Total answers: 3

How to prevent embedded python to exit() my process

How to prevent embedded python to exit() my process Question: I’m having trouble while running embedded python. It turns out that I can’t capture that SystemExit exception raised by sys.exit(); This is what I have so far: $ cat call.c #include <Python.h> int main(int argc, char *argv[]) { Py_InitializeEx(0); PySys_SetArgv(argc-1, argv+1); if (PyRun_AnyFileEx(fopen(argv[1], “r”), argv[1], …

Total answers: 2

Doing something before program exit

Doing something before program exit Question: How can you have a function or something that will be executed before your program quits? I have a script that will be constantly running in the background, and I need it to save some data to a file before it exits. Is there a standard way of doing …

Total answers: 6