Penguin

Differences between current version and revision by previous author of PythonNotes.

Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History

Newer page: version 7 Last edited on Tuesday, April 22, 2008 9:13:42 am by JohnMcPherson
Older page: version 2 Last edited on Monday, October 18, 2004 2:59:12 am by AristotlePagaltzis Revert
@@ -1,5 +1,6 @@
 !!! Timezones and [Python] < 2.3 
+  
  
 [Python] 2.3 has made some impressive leaps forward in its support of timezones and the classes that it makes available to handle them. If you are doing anything that uses timezones even remotely you will save yourself a __lot__ of hassle by not using a version of [Python] older than 2.3! If for some reason you're stuck with [Python] < 2.3 (like you run a pathetically old distro like [Woody]) then watch out for the following. 
  
 !! strptime 
@@ -12,7 +13,30 @@
  <verbatim> 
  ptime = time.strptime("2004-10-06 10:00:00", "%Y-%m-%d %H:%M:%S")[:8] + (-1,) 
  </verbatim> 
  This is what [Python] 2.3 does, implicitly. 
+  
+!!! threads  
+  
+!! subprocess module  
+If you use the ''subprocess'' module to spawn a child in one of your threads and you are using locks, there is a possibility of a deadlock. See the discussion in the [python newsgroup|http://groups.google.com/group/comp.lang.python/browse_thread/thread/5fae8a453c95ae89/42f5c9f9215dbb1e#42f5c9f9215dbb1e]. Basically, python internally uses locks during imports, and you can fix it in this instance by moving the ''"from errno import ENOENT, ENOTDIR"'' line from the ''_execvpe'' function in the os.py module up to the top, so that it doesn't happen after the fork(). This affects python 2.4 at least, not sure if it's fixed in 2.5.  
+  
+The ''subprocess'' module is also buggy if you have multiple threads using subprocess to create child processes. Basically, it isn't thread-safe when checking if a child has finished, and you occasionally get "<tt>~[Errno 10] No child processes</tt>" exceptions. See [mailing list thread|http://www.mail-archive.com/python-bugs-list@python.org/msg12685.html].  
+  
+!! python-gtk  
+If you want to do ''thread.start_new_thread()'' from within an app using pygtk, you need to call ''gtk.gdk.threads_init()'' first, otherwise the gtk event loop will screw you up.  
+  
+!!! Miscallaneous  
+  
+!! os.getlogin()  
+The ''getlogin()'' function is supposed to return the username of the owner of the process. Unfortunately this works by looking in utmp(5),  
+and most terminal emulators in linux don't bother creating a new record for each window. This means the OS returns "ENOENT", and python  
+happily prints out <tt>OSError: ~[Errno 2] No such file or directory</tt>. On Linux/POSIX systems, you are probably better off doing:  
+<verbatim>  
+import os  
+import pwd  
+username = pwd.getpwuid(os.geteuid())[0]  
+</verbatim>  
+  
  
 ---- 
 CategoryProgramming, CategoryNotes