Code changes behaviour after first run

This is the place for queries that don't fit in any of the other categories.

Code changes behaviour after first run

Postby sboden » Mon Apr 14, 2014 8:28 pm

Just wondering if anyone had my python problem before or knows exactly the root cause:

I'm experimenting making a python v3 version of mechanize (the web scraping library)... still ongoing... did the 2to3 conversions, did some rewrites. Basic code is working. However... I run my small stateless test program once and it works, a side effect is that the python files in the library are compiled. I run the test program again and the program fails... I erase 1 specific compiled python file, rerun the test program and it works again.

The above I can do consistently... First time around the code works, it doesn't work if one library was already compiled, and it works again if I remove the compiled file and run it again.

In PyCharm the test program always works (guessing they compile on the fly).

Last edited by stranac on Mon Apr 14, 2014 8:38 pm, edited 1 time in total.
Reason: First post lock.
Posts: 6
Joined: Mon Apr 14, 2014 8:22 pm

Re: Code changes behaviour after first run

Postby DrakeMagi » Tue Apr 15, 2014 12:48 am

would be nice to see the test program ?

would also be great to know what specfic file you erase ?
Linux: won't find windows here.
Linux: the choice of a GNU generation.
Posts: 112
Joined: Sun May 12, 2013 8:36 pm

Re: Code changes behaviour after first run

Postby sboden » Tue Apr 15, 2014 9:16 am

My small test program below in code section. It's just opening google with mechanize v3 and then "dumping forms". The compiled file in question I erase is mechanize\

But in general... what could be the cause that python runs differently when the file is not compiled yet, compared to when the file is compiled upfront. I would guess that execution would be the same in either case... either python doesn't find a compiled file, compiles it and uses or it would either use the precompiled file of a previous run.

It's very strange, but it is consistent... no precompiled python file everything works, is already precompiled it fails. I'm using activestate python v3.3.4.1 on Windows 7 for the moment.


Code: Select all
import mechanize

# Browser
br = mechanize.Browser()

# Browser options

# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)

# Want debugging messages?

# User-Agent (this is cheating, ok?)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]

r ='')
#html =

for f in br.forms():

Posts: 6
Joined: Mon Apr 14, 2014 8:22 pm

Return to General Coding Help

Who is online

Users browsing this forum: Bing [Bot] and 6 guests