I am new to CellProfiler and trying to run headless mode with custom script. I am facing issue where my program is running fine with old version of CellProfiler but when i try to run it from latest version of CellProfiler (Latest code from git) it is generating output and not exiting to terminal. Looks like process is waiting or something is blocking it. Attached is my .py file which i am running using “python CelrofilerTest.py -i/home/ubuntu/dev/CellProfilerNew/5_4_4.jpg -o/home/ubuntu/dev/test_new3.jpg -1”. It will run fine with older version of CellProfiler, it will also run with latest version but will wait after running Pipeline. Need to use CTRL + C to exit the process.
CellProfilerTest.py (4.72 KB)
I suggest ending your code with the following:
if __name__ == "__main__":
Thanks for your reply. I am calling this function from another python application. I have already tried this, but it will stop caller application also. In older cellprofiler it is working without os._exit(0).
Instantiating a pipeline (cpp.Pipeline()) will start Java and that will start some threads that will prevent your script from exiting. You might try:
from cellprofiler.utilities.jutil import kill_vm try: kill_vm() except: # only will get here in unusual circumstances or if the Java bridge wasn't started os._exit(0)
I have added kill_vm() and it is working fine from terminal (when i call program from terminal), but when i try to call this python program from other python program (In Different directory) as shown code below it is causing issue and not returning to terminal
import os import importlib def main(): print "Starting server..." pyModule = __import__("CellProfilerTest") pyFunction = getattr(pyModule, "deconvolve") #Method name can be anything output = pyFunction("/home/ubuntu/dev/5_4_4.jpg", "/home/ubuntu/dev/rab/destination/test_new2.jpg") #Method parameters if __name__ == '__main__': main() print 'Test'
I have resolved the issue by changing python caller code. Now it is working fine.