Movatterモバイル変換
[0]ホーム
Clean-up of threaded server
David Bolendb3l at fitlinxx.com
Mon Apr 9 13:44:38 EDT 2001
Michael =?iso-8859-1?Q?Str=F6der?= <michael at stroeder.com> writes:> I have two problems:>> 1. The server process does not detach from the console anymore (fork> is used for that). This seems to work without the separate helper> thread.>> 2. For testing purposes the server process can be started> non-detached. In this case KeyboardInterrupt is catched by the main> thread to shut down the process. This does not work with the helper> thread but works without it.I'm not sure about (1) (perhaps depending on environment, the otherthread has its own reference to file handles that you normally closebefore detaching, and you could try closing them before starting upthe thread?)But for (2) if you have multiple threads around, then Python is goingto wait for those other threads to terminate when you try to exit(it's basically the same as you doing a join() on each thread). So toproperly exit, you would want to write your helper threads to look forsome sort of sentinel or receive a message to tell them to exit whenyou want the script to exit.Alternatively, threads can be marked as a "daemon" via the threadingmodule setDaemon method, and those threads are permitted to still beexecuting when the script exits.---- David-- /-----------------------------------------------------------------------\ \ David Bolen \ E-mail:db3l at fitlinxx.com / | FitLinxx, Inc. \ Phone: (203) 708-5192 | / 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \\-----------------------------------------------------------------------/
More information about the Python-listmailing list
[8]ページ先頭