Bug #60982 Import from disk fails: 'module' object has no attribute 'STARTF_USESHOWWIND'
Submitted: 26 Apr 2011 21:12 Modified: 18 May 2011 1:51
Reporter: Erwin Derksen Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Workbench: Administration Severity:S2 (Serious)
Version:5.2.33b OS:Microsoft Windows (Vista)
Assigned to: CPU Architecture:Any

[26 Apr 2011 21:12] Erwin Derksen
Description:
On trying to import a file from disk I consistently get the folowing error:

------------------------
Output on import screen:
------------------------
22:58:41 Restoring D:\Projecten\data.mysql

Running: mysql.exe --defaults-extra-file="c:\users\erwin\appdata\local\temp\tmptvcozs.cnf"   --host=127.0.0.1 --user=root --port=3306 --default-character-set=utf8 --comments < "D:\\Projecten\\data.mysql"

Error executing task: 'module' object has no attribute 'STARTF_USESHOWWINDOW'
Error executing task local variable 'p1' referenced before assignment

22:58:41 Import of D:\Projecten\data.mysql has finished

-----------------------------
Output on system info screen:
-----------------------------
WMIShell: Set filters for local windows cli

Traceback (most recent call last):

  File "D:\Program Files\MySQL\MySQL Workbench 5.2 CE\modules\wb_admin_export.py", line 126, in process_db

    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW

AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'

Traceback (most recent call last):

  File "D:\Program Files\MySQL\MySQL Workbench 5.2 CE\modules\wb_admin_export.py", line 202, in run

    exitcode = self.process_db(pipe, task.extra_arguments, task.objec_names)

  File "D:\Program Files\MySQL\MySQL Workbench 5.2 CE\modules\wb_admin_export.py", line 157, in process_db

    err = p1.stderr.read()

UnboundLocalError: local variable 'p1' referenced before assignment

22:58:41 Restoring D:\Projecten\data.mysql

Running: mysql.exe --defaults-extra-file="c:\users\erwin\appdata\local\temp\tmptvcozs.cnf"   --host=127.0.0.1 --user=root --port=3306 --default-character-set=utf8 --comments < "D:\\Projecten\\data.mysql"

Error executing task: 'module' object has no attribute 'STARTF_USESHOWWINDOW'

Error executing task local variable 'p1' referenced before assignment

MySQL Workbench CE for Windows version 5.2.33
Configuration Directory: C:\Users\erwin\AppData\Roaming\MySQL\Workbench
Data Directory: D:\Program Files\MySQL\MySQL Workbench 5.2 CE
Cairo Version: 1.8.8
Rendering Mode: OpenGL is available on this system, so OpenGL is used for rendering.
OpenGL Driver Version: 3.2.0
OS: Microsoft Windows Vista Business Edition Service Pack 2 (build 6002), 32-bit
CPU: 2x Intel(R) Core(TM)2 Duo CPU     T7500  @ 2.20GHz, 2.0 GiB RAM
Active video adapter: NVIDIA GeForce 8600M GT    
Installed video RAM: 256 MB
Current video mode: 1920 x 1200 x 4294967296 kleuren
Used bit depth: 32
Driver version: 8.17.11.9562
Installed display drivers: nvd3dum.dll,nvwgf2um.dll,nvwgf2um.dll
Current user language: Nederlands (Nederland)

How to repeat:
Open a server administrsation screen - data export and restore - import from disk - select import from Self-Contained file - select a file - start import
[27 Apr 2011 12:47] Miguel Solorzano
I couldn't repeat on Vista Ultimate 64-bit with Sakila example database. Are you able to provide your SQL files?. Thanks in advance.
[27 Apr 2011 13:15] Alfredo Kojima
Do you have a python interpreter installed? If so, that may be a conflict with the WB shipped one, caused by a bug that has been fixed recently.
[27 Apr 2011 13:53] Erwin Derksen
I could provide an SQL file, but import consistently fails on my system. So it won't be due to the content of the file to import (the error appears so fast it that I think the file hasn't even been opened).

So it probably comes down to a system configuration setup that is not handled. Thus, your remark about Python versions seems closer to the problem. As I also use Hg Mercurial source control (that doesn't come with its own version of python), I indeed also have Python installed on my system as a standalone application. Looking at my list of installed programs I have even both Python 2.5.4 and 2.6.6 installed.

Note: a former version of workbench (2.5.16) worked fine on my system. Only after upgrading to 5.2.29 and later to 5.2.33 and even 5.2.33b the error started appearing. But then, perhaps in between that same time I upgraded Mercurial and, as a requirement, the Python version.

Some searching on the first error message (object has no attribute STARTF_USESHOWWINDOW) directed me to these link:
http://web.archiveorange.com/archive/v/5H3d1ZrPVqSmi86w1StG
that directed me to this link:
http://svn.python.org/view/python/tags/r27/Lib/subprocess.py?r1=79064&r2=82504
Or this one:
http://stackoverflow.com/questions/4703983/module-subprocess-has-no-attribute-startf-usesh...

I don't know enough python to see if the solution given in the latter could be a workaround for me.
[27 Apr 2011 14:12] Alfredo Kojima
Please try the package from ftp://ftp.mysql.com/pub/mysql/download/gui-tools/mysql-workbench-gpl-snapshot-5.2.34.7605-...
(just for testing, it's an early development build, so there's untested and unfinished things in it).
[27 Apr 2011 14:48] Erwin Derksen
Thanks for your very fast response. Unfortunately however, I get an error on downloading the link (Error 324 (net::ERR_EMPTY_RESPONSE) on Chrome, 500 OOPS: vsf_sysutil_bind on firefox, and with fireftp I can't browse to the correct dir getting the same error as on firefox)
[28 Apr 2011 10:11] Erwin Derksen
OK, today the download worked but the import still failed. Based on the article on Stackoverflow (http://stackoverflow.com/questions/4703983/module-subprocess-has-no-attribute-startf-usesh...) I changed the following in file wb_admin_export.py:

added line 22:
import _subprocess

changed lines 127/128 (added the underscores):
                    info.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
                    info.wShowWindow = _subprocess.SW_HIDE

And now import works fine, both in the downloaded 5.2.34 and 5.2.33b. I leave it up to you to see:
- if the "import _subprocess" will work fine on other (non Windows) systems (the other changed lines are only executed on Windows)
- if _subprocess will be defined in other allowed Python versions.
[28 Apr 2011 10:20] Erwin Derksen
Note: the constants (STARTF_USESHOWWIND and SW_HIDE) are also used in wba_monitor_be.py. You will probably have to apply the same changes over there.
[28 Apr 2011 12:26] Alfredo Kojima
Hi

Could you please add the following line in wb_admin_export.py, after the import statements at the top of the file and then send us its output, which should be printed to the Output window?

print "subprocess module path:", subprocess.__file__
[28 Apr 2011 12:52] Erwin Derksen
That was easier said than done, I finally found a file wb.log that seems to contain stdout output of wb, see below:. The answer thus is:

C:\Program Files\Python26\Lib\subprocess.pyc

14:44:30 [   Info][      wbprivate]: WbContext::init
14:44:37 [   Info][      wbprivate]: Starting tunnel
14:44:55 [   Info][     grt.python]: subprocess module path:
14:44:55 [   Info][     grt.python]:  
14:44:55 [   Info][     grt.python]: C:\Program Files\Python26\Lib\subprocess.pyc
14:44:55 [   Info][     grt.python]: 

14:44:55 [   Info][     grt.python]: 14:44:55 Restoring D:\Projecten\data.mysql

14:44:55 [   Info][     grt.python]: 

14:44:55 [   Info][     grt.python]: Running: mysql.exe --defaults-extra-file="c:\users\erwin\appdata\local\temp\tmpwicrse.cnf"   --host=margrietslaptop --user=root --port=3306 --default-character-set=utf8 --comments < "D:\\Projecten\\data.mysql"

14:44:55 [   Info][     grt.python]:
[28 Apr 2011 14:48] Alfredo Kojima
Please open the scripting shell (in Scripting menu) and in the prompt type:
import sys
print sys.path
import os
print os.environment

then paste the output here.
[28 Apr 2011 15:13] Erwin Derksen
Thanks for the effort you put into this. I get the following output (I added line breaks after the comma's for readability)
> run

['D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE/python/site-packages',
 'D:\\dev',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\python26.zip',
 'C:\\Program Files\\Python26\\Lib',
 'C:\\Program Files\\Python26\\DLLs',
 'C:\\Program Files\\Python26\\Lib\\lib-tk',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE',
 'C:\\Program Files\\Python26', 'C:\\Program Files\\Python26\\lib\\site-packages',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\python',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\modules']

Uncaught exception while executing C:\Users\erwin\AppData\Roaming\MySQL\Workbench\scripts\test.py:

  File "c:\users\erwin\appdata\roaming\mysql\workbench\scripts\test.py", line 12, in <module>

    print os.environment

AttributeError: 'module' object has no attribute 'environment'

> stop

Execution finished

If os.environment was meant to get the value PATH:
PATH = D:\Program Files\GnuWin32\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Intel\WiFi\bin\;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Common Files\DivX Shared\;D:\Program Files\MySQL\MySQL Server 5.5\bin;D:\Program Files\MySQL\MySQL Workbench 5.2;C:\Program Files\ImageMagick-6.6.1-Q16;D:\Program Files\TortoiseHg\;"D:\Program Files\Zend\ZendServer\bin";"D:\Program Files\Zend\ZendServer\share\ZendFramework\bin";D:\Program Files\Git\cmd;
[28 Apr 2011 16:04] Alfredo Kojima
Sorry, was supposed to be print os.environ (Yes, I need the value of PATH, but I need the one that WB is seeing, so please repeat the test with os.environ)
Was that output from the test binary?  If not, can you try with it? With this extra information, it should be enough to fix the issue. 
The problem seems to be that your own installation of Python is not being ignored by WB, as it was supposed to be.
[28 Apr 2011 16:24] Erwin Derksen
OK, I unzipped that test version again and ran the script in that version:

script (interactive command line doesn't react to my keyboard input:
--------------------------------------------------------------------
# -*- coding: utf-8 -*-
# MySQL Workbench Python script
# <description>
# Written in MySQL Workbench 5.2.34

import grt
#import mforms

import sys
print sys.path
import os
print os.environ

Output (newlines inserted after comma's):
-----------------------------------------
Script saved as C:\Users\erwin\AppData\Roaming\MySQL\Workbench\scripts\test.py

> run

['D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE/python/site-packages',
 'D:\\dev',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python\\DLLs',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python\\Lib',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\python27.zip',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python\\lib\\plat-win',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python\\lib\\lib-tk',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\python',
 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\modules']

{'TMP': 'C:\\Users\\erwin\\AppData\\Local\\Temp',
 'COMPUTERNAME': 'ERWINSLAPTOP',
 'USERDOMAIN': 'erwinslaptop',
 'PSMODULEPATH': 'C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules\\',
 'VS90COMNTOOLS': 'C:\\Program Files\\Microsoft Visual Studio 9.0\\Common7\\Tools\\',
 'COMMONPROGRAMFILES': 'C:\\Program Files\\Common Files',
 'PROCESSOR_IDENTIFIER': 'x86 Family 6 Model 15 Stepping 11, GenuineIntel',
 'PROGRAMFILES': 'C:\\Program Files',
 'PROCESSOR_REVISION': '0f0b',
 'HOME': 'C:\\Users\\erwin',
 'PATH': 'D:\\Program Files\\GnuWin32\\bin;C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Program Files\\Intel\\WiFi\\bin\\;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Common Files\\DivX Shared\\;D:\\Program Files\\MySQL\\MySQL Server 5.5\\bin;D:\\Program Files\\MySQL\\MySQL Workbench 5.2;C:\\Program Files\\ImageMagick-6.6.1-Q16;D:\\Program Files\\TortoiseHg\\;"D:\\Program Files\\Zend\\ZendServer\\bin";"D:\\Program Files\\Zend\\ZendServer\\share\\ZendFramework\\bin";D:\\Program Files\\Git\\cmd;',
 'ROXIOCENTRAL': 'C:\\Program Files\\Common Files\\Roxio Shared\\9.0\\Roxio Central33\\',
 'COMSPEC': 'C:\\Windows\\system32\\cmd.exe',
 'TEMP': 'C:\\Users\\erwin\\AppData\\Local\\Temp',
 'PROCESSOR_ARCHITECTURE': 'x86',
 'ALLUSERSPROFILE': 'C:\\ProgramData',
 'SESSIONNAME': 'Console',
 'HOMEPATH': '\\Users\\erwin',
 'USERNAME': 'erwin',
 'LOGONSERVER': '\\\\ERWINSLAPTOP',
 'SYSTEMROOT': 'C:\\Windows',
 'LOCALAPPDATA': 'C:\\Users\\erwin\\AppData\\Local',
 'PROGRAMDATA': 'C:\\ProgramData',
 'PYTHONPATH': 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python;D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python\\DLLs;D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python\\Lib',
 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC',
 'FP_NO_HOST_CHECK': 'NO',
 'WINDIR': 'C:\\Windows',
 'APPDATA': 'C:\\Users\\erwin\\AppData\\Roaming',
 'HOMEDRIVE': 'C:',
 'SYSTEMDRIVE': 'C:',
 'PYTHONHOME': 'D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\Python',
 'NUMBER_OF_PROCESSORS': '2',
 'PROCESSOR_LEVEL': '6',
 'OS': 'Windows_NT',
 'PUBLIC': 'C:\\Users\\Public',
 'USERPROFILE': 'C:\\Users\\erwin'}

Execution finished
---------------------------------------

Wrong slashes in this sys.path part: D:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE/python/site-packages'????
[28 Apr 2011 17:38] Alfredo Kojima
The mixed slashes / in the path shouldn't matter. But now I'm confused, as nothing in your environment points to the other Python dir. What does import subprocess
print dir(subprocess)
print subprocess.__file__
show for you in the test binary?
[28 Apr 2011 18:40] Erwin Derksen
I ran this script in the scripting shell (added some lines to discover if there are differences between the shell and the import process):
-------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
# MySQL Workbench Python script
# <description>
# Written in MySQL Workbench 5.2.34

import grt
#import mforms

import subprocess
print dir(subprocess)
print subprocess.__file__

info = subprocess.STARTUPINFO()
info.dwFlags |= subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

With this as result:
--------------------
Script saved as C:\Users\erwin\AppData\Roaming\MySQL\Workbench\scripts\test.py

> run

['CREATE_NEW_CONSOLE', 'CREATE_NEW_PROCESS_GROUP', 'CalledProcessError', 'MAXFD', 'PIPE', 'Popen', 'STARTUPINFO', 'STDOUT', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_active', '_cleanup', '_demo_posix', '_demo_windows', '_eintr_retry_call', '_subprocess', 'call', 'check_call', 'check_output', 'gc', 'list2cmdline', 'msvcrt', 'mswindows', 'os', 'pywintypes', 'signal', 'sys', 'threading', 'traceback', 'types']

D:\Program Files\MySQL\MySQL Workbench 5.2 CE\Python\Lib\subprocess.pyc

Uncaught exception while executing C:\Users\erwin\AppData\Roaming\MySQL\Workbench\scripts\test.py:

  File "c:\users\erwin\appdata\roaming\mysql\workbench\scripts\test.py", line 14, in <module>

    info.dwFlags |= subprocess.STARTF_USESHOWWINDOW

AttributeError: 'module' object has no attribute 'STARTF_USESHOWWINDOW'

To be sure, I added these lines to the import code and ran the import once again:
--------------------------------------------------------------------------
                    self.print_log_message("subprocess dir: %s" % dir(subprocess))
                    self.print_log_message("subprocess file: %s" % subprocess.__file__)

With this result:
-----------------
subprocess dir: ['CREATE_NEW_CONSOLE', 'CREATE_NEW_PROCESS_GROUP', 'CalledProcessError', 'MAXFD', 'PIPE', 'Popen', 'STARTUPINFO', 'STDOUT', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '_active', '_cleanup', '_demo_posix', '_demo_windows', '_eintr_retry_call', '_subprocess', 'call', 'check_call', 'check_output', 'gc', 'list2cmdline', 'msvcrt', 'mswindows', 'os', 'pywintypes', 'signal', 'sys', 'threading', 'traceback', 'types']
subprocess file: D:\Program Files\MySQL\MySQL Workbench 5.2 CE\Python\Lib\subprocess.pyc
Error executing task: 'module' object has no attribute 'STARTF_USESHOWWINDOW'

Looking at D:\Program Files\MySQL\MySQL Workbench 5.2 CE\Python\Lib\subprocess.py, line 853 and 854 I see that the module itself also uses _subprocess (thus with an underscore) ...
[18 May 2011 1:51] Paul Dubois
Noted in 5.2.34 changelog.

File import operations failed with these errors:

Error executing task: 'module' object has no attribute 'STARTF_USESHOWWINDOW' 
Error executing task local variable 'p1' referenced before assignment