atexit

Python Multiprocessing atexit Error “Error in atexit._run_exitfuncs”

大兔子大兔子 提交于 2019-12-04 02:43:51
I am trying to run a simple multiple processes application in Python. The main thread spawns 1 to N processes and waits until they all done processing. The processes each run an infinite loop, so they can potentially run forever without some user interruption, so I put in some code to handle a KeyboardInterrupt: #!/usr/bin/env python import sys import time from multiprocessing import Process def main(): # Set up inputs.. # Spawn processes Proc( 1).start() Proc( 2).start() class Proc ( Process ): def __init__ ( self, procNum): self.id = procNum Process.__init__(self) def run ( self ): doneWork

python 2.6.x theading / signals /atexit fail on some versions?

妖精的绣舞 提交于 2019-12-03 08:03:47
I've seen a lot of questions related to this... but my code works on python 2.6.2 and fails to work on python 2.6.5. Am I wrong in thinking that the whole atexit "functions registered via this module are not called when the program is killed by a signal" thing shouldn't count here because I'm catching the signal and then exiting cleanly? What's going on here? Whats the proper way to do this? import atexit, sys, signal, time, threading terminate = False threads = [] def test_loop(): while True: if terminate: print('stopping thread') break else: print('looping') time.sleep(1) @atexit.register

dlclose() does not call the destructor of global objects

余生颓废 提交于 2019-12-03 05:46:19
问题 plugin1.cpp: #include <iostream> static class TestStatic { public: TestStatic() { std::cout << "TestStatic create" << std::endl; } ~TestStatic() { std::cout << "TestStatic destroy" << std::endl; } } test_static; host.cpp #include <dlfcn.h> #include <iostream> int main(int argc,char *argv[]) { void* handle = dlopen("./plugin1.so",RTLD_NOW | RTLD_LOCAL ); dlclose(handle); return 0; } build and run: >g++ -c plugin1.cpp -o plugin1.o -fPIC >g++ -shared plugin.o -o plugin1.so >g++ host.cpp -o host

atexit function is not called when exiting the script using Ipython

余生长醉 提交于 2019-12-02 06:22:21
Below is the code written in a script say test_atexit.py def exit_function(): print "I am in exit function" import atexit atexit.register(exit_function) print "I am in main function" When i run the function using python2.4 then exit_function is being called $python2.4 test_atexit.py I am in main function I am in exit function When i run the same using ipython then exit_function is not being called $ ipython In [1]: %run test_atexit.py I am in main function In [2]: why exit_function is not called when running script using Ipython and how can i make ipython to call exit_function atexit functions

Exists a way to free memory in atexit or similar without using global variables?

≯℡__Kan透↙ 提交于 2019-12-01 05:54:01
I am developing a project in C, and I need to free the allocated memory and also close all the open files before it exits. I decided to implement a clean function that will do all this stuff and call it with atexit because there are a lot of possible exit scenarios. The problem is that atexit doesn't allow me to set functions with parameters, so I can't send to clean the pointers that need to be freed in the end of the process. So I need to declare as global variables every pointer that may need to be freed, and every file that may remaining open in the program? (I already did that but doesn't

.NET code execution at normal process exit?

孤人 提交于 2019-11-30 20:29:05
In C there is the atexit function, which The atexit() function registers the given function to be called at normal process termination, either via exit(3) or via return from the program's main(). Python has a similar capability. Does .NET provide a way to call code at normal process termination? I know there are certain things like DomainUnload and ProcessExit , but at least as far as I can tell, these are unreliable - either requiring the application to be a Windows Forms (or WPF app), or something else. I am writing code for a .dll, so I can't rely on things like mucking with the main

.NET code execution at normal process exit?

心已入冬 提交于 2019-11-30 05:02:48
问题 In C there is the atexit function, which The atexit() function registers the given function to be called at normal process termination, either via exit(3) or via return from the program's main(). Python has a similar capability. Does .NET provide a way to call code at normal process termination? I know there are certain things like DomainUnload and ProcessExit , but at least as far as I can tell, these are unreliable - either requiring the application to be a Windows Forms (or WPF app), or

Python Process won't call atexit

跟風遠走 提交于 2019-11-29 13:23:05
I'm trying to use atexit in a Process , but unfortunately it doesn't seem to work. Here's some example code: import time import atexit import logging import multiprocessing logging.basicConfig(level=logging.DEBUG) class W(multiprocessing.Process): def run(self): logging.debug("%s Started" % self.name) @atexit.register def log_terminate(): # ever called? logging.debug("%s Terminated!" % self.name) while True: time.sleep(10) @atexit.register def log_exit(): logging.debug("Main process terminated") logging.debug("Main process started") a = W() b = W() a.start() b.start() time.sleep(1) a.terminate

Freeing in an atexit()

 ̄綄美尐妖づ 提交于 2019-11-29 09:29:35
Is there any point to freeing memory in an atexit() function? I have a global variable that gets malloc'ed after startup. I could write an atexit() function to free it, but isn't the system going to reclaim all that memory when the program exits anyway? Is there any benefit to being tidy and actively cleaning it up myself? Not in C - it's like rearranging the deck chairs while the ship sinks around you. In C++ the answer is different, because objects can delete temporary files and so forth in their destructors, so you need to make sure those get called. One benefit on freeing it is that if you

Python Process won't call atexit

独自空忆成欢 提交于 2019-11-28 06:58:46
问题 I'm trying to use atexit in a Process , but unfortunately it doesn't seem to work. Here's some example code: import time import atexit import logging import multiprocessing logging.basicConfig(level=logging.DEBUG) class W(multiprocessing.Process): def run(self): logging.debug("%s Started" % self.name) @atexit.register def log_terminate(): # ever called? logging.debug("%s Terminated!" % self.name) while True: time.sleep(10) @atexit.register def log_exit(): logging.debug("Main process