From: SourceForge.net <no...@so...> - 2006-11-26 16:24:22
|
Bugs item #1603253, was opened at 2006-11-26 22:22 Message generated for change (Settings changed) made by batyi You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1603253&group_id=12867 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. >Category: Library Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Petr Gladkikh (batyi) Assigned to: Nobody/Anonymous (nobody) Summary: Thread's setDaemon setting does not work Initial Comment: One can not create "daemon" thread using Jython's threading.Thread class. Probably simplest code that reveals the problem is (this should be main thread): from threading import Thread def worker(): while 1: pass thread = Thread(target=worker, name="daemon-thread") thread.setDaemon(1) thread.start() CPython exits almost immediately as expected. Jython hangs indefinitely (in all versions iI have tested - 2.1, 2.2alpha and repository trunk revision 2989). There is a suggestion in jython-users mailing list http://sourceforge.net/mailarchive/message.php?msg_id=11041636 regarding this behaviour. Note that only way to make Java Thread class instance to be daemon is to call "setDaemon()" method (there's no appropriate constuctor arguments to do that). There's also similar restriction in Java and Python: "daemon" status can be set only before a thread is started. So I think the solution that is suggested in message above is correct. I'll copy corrected function here for completeness: public static void start_new_thread(PyObject func, PyTuple args) { Thread pt = new FunctionThread(func, args.list); PyObject currentThread = func.__findattr__("im_self"); if(currentThread != null) { PyObject isDaemon = currentThread.__getattr__("isDaemon"); boolean d = isDaemon.__call__().__nonzero__(); pt.setDaemon(d); } pt.start(); } ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=112867&aid=1603253&group_id=12867 |