Trouble converting hex to decimal?
I'm trying to process the IP packet length field, as recorded by pcap (Ethereal) and recovered using pcapy. When I slice out those bytes, I get a value that shows in '\x00' format, rather than '0x00'. Neither int() nor eval() are working. How do I handle this? Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
Can't get pcap file scanner to terminate normally
I'm using pcapy to scan a packet capture file. I've tried a variety of tests to end the loop at EOF, but can't seem to avoid the program terminating with a pcapy.PcapError. I've tested for empty lists (while Raw == [] or Passed == []:) and strings (while Raw ==""] or Passed == "":) as well as the test in the sample below. while Raw and Passed : if Raw_IP != Passed_IP: Dropped.dump(Raw_hdr, Raw_data) else: Passed_hdr, Passed_data = Passed.next() Raw_hdr, Raw_data = Raw.next() -- http://mail.python.org/mailman/listinfo/python-list
passing lists
I have a program in which I'm passing a list to functions. When I reference an element in a function to which it is passed, I get the error message "unsubscriptable object". When printing the list contents in that same function, I get "xxx is ". How do I pass a list? Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
Re: passing lists
def Match(..., Raw_packet_queue, ...): ... print 'in Match, Raw_Packet_queue is', Raw_packet_queue # this returns 'Reader object at 0xaaa' ... return [Last_Passed, Last_Dropped, Raw_packet_queue] # this causes 'unsubscriptable object'error message #* def Main(...): Raw_packet_queue = [] ... Raw_packet_queue = enqueue(..., Raw_packet_queue, ...) # this works ... if Raw_packet_queue[ctr][1] == Passed_IP: Last_Passed, Last_Dropped, Raw_packet_queue = Match(..., Raw_packet_queue, ...) # the problem starts here ... On Wed, 2005-03-02 at 14:09, Bill Mill wrote: > Earl, > > Please post the smallest snippet of code you can which illustrates > your problem. No list is an unsubscriptable object, so you seem to be > passing something that is not a list to your function. > > As it stands, you don't give enough information to give an actual answer. > > Peace > Bill Mill > bill.mill at gmail.com > > > On Wed, 02 Mar 2005 14:05:18 -0700, Earl Eiland <[EMAIL PROTECTED]> wrote: > > I have a program in which I'm passing a list to functions. When I > > reference an element in a function to which it is passed, I get the > > error message "unsubscriptable object". When printing the list contents > > in that same function, I get "xxx is ". How do > > I pass a list? > > > > Earl Eiland > > > > -- > > http://mail.python.org/mailman/listinfo/python-list > > -- http://mail.python.org/mailman/listinfo/python-list
Re: passing lists
This message contains the responses to two previous messages: In response to Steven B.,the statements Raw_packet_queue = enqueue(..., Raw_packet_queue, ...) print 'Sort 1 Raw_packet_queue is', Raw_packet_queue produce the output Sort 1 Raw_packet_queue is [[(, '\x00\x00\xd1\xf0\x [EMAIL PROTECTED] 81\x8a\x02\xbf\xb1\x13\x00\x16\xe5/\xd5\xa7vu\x0e\x08\x80\x10\xf8\xe0\x8a[\x00\x 00\x01\x01\x08\n\x15\xb7\x13\xba\x8e\x91\x9a\xfd'), ['E\x00\x004', '@\x00', '\x0 6', '\x89N\xa2j\x81\x8a\x02\xbf\xb1\x13\x00\x16\xe5/\xd5\xa7vu\x0e\x08\x80\x10\x f8\xe0\x8a[\x00\x00\x01\x01\x08\n\x15\xb7\x13\xba\x8e\x91\x9a\xfd']]] This consists of two lists [[pcap packet header, pcap packet body], [a list of selected IP header fields]]. Raw_packet_queue[0][0][1] should return the 'pcap packet body' list element. In response to Steve H., the traceback is Traceback (most recent call last): File "../Devel_2.py", line 125, in ? Inbound_Results = Parser.Sort(Inb_sequence, "Inbound-dump-"+Run_ID+"-Dropped .dmp", "Inbound-dump-"+Run_ID+"-Created.dmp") File "/home/earl/ResearchProjects/IntrusionResistance/NewPhasee2/Parser.py", l ine 291, in Sort if Raw_packet_queue[ctr][1] == Passed_IP: Last_Passed, Last_Dropped, Raw_pac ket_queue = Match(Created, Passed, Raw_packet_queue, Raw, False, Last_Passed, La st_Dropped, First_Created, ctr) File "/home/earl/ResearchProjects/IntrusionResistance/NewPhasee2/Parser.py", l ine 132, in Match Last_Passed = Raw_packet_queue[0][0][1] TypeError: unsubscriptable object On Wed, 2005-03-02 at 15:34, Steve Holden wrote: > Earl Eiland wrote: > > def Match(..., Raw_packet_queue, ...): > > ... > > print 'in Match, Raw_Packet_queue is', Raw_packet_queue # this returns > > 'Reader object at 0xaaa' > > ... > > return [Last_Passed, Last_Dropped, Raw_packet_queue] # this causes > > 'unsubscriptable object'error message > > > > #* > > def Main(...): > > Raw_packet_queue = [] > > ... > > Raw_packet_queue = enqueue(..., Raw_packet_queue, ...) # this works > > ... > > if Raw_packet_queue[ctr][1] == Passed_IP: Last_Passed, Last_Dropped, > > oops! > > Raw_packet_queue = Match(..., Raw_packet_queue, ...) # the problem > > starts here > > ... > > > Rule one: ALWAYS include the actual traceback, rather than providing > your interporetation of what it means (though you are then free to do > that, too). > > What makes you think it's the Match() call that's causing the problem? > > I'd be willing to bet money it's the double-subscripting of > Raw_packet_queue - if item [ctr] on the Raw_packet_queue isn't a list or > a dict then subscripting it by [1] will give you the error message that > you quote. > > But if you had included the traceback you would have made it unnecessary > for me to use my psychic powers :-) > > regards > Steve > > > On Wed, 2005-03-02 at 14:09, Bill Mill wrote: > > > >>Earl, > >> > >>Please post the smallest snippet of code you can which illustrates > >>your problem. No list is an unsubscriptable object, so you seem to be > >>passing something that is not a list to your function. > >> > >>As it stands, you don't give enough information to give an actual answer. > >> > >>Peace > >>Bill Mill > >>bill.mill at gmail.com > > > > > >> > >>On Wed, 02 Mar 2005 14:05:18 -0700, Earl Eiland <[EMAIL PROTECTED]> wrote: > >> > >>>I have a program in which I'm passing a list to functions. When I > >>>reference an element in a function to which it is passed, I get the > >>>error message "unsubscriptable object". When printing the list contents > >>>in that same function, I get "xxx is ". How do > >>>I pass a list? > >>> > >>>Earl Eiland > >>> > >>>-- > >>>http://mail.python.org/mailman/listinfo/python-list > >>> > > > > > -- > Meet the Python developers and your c.l.py favorites March 23-25 > Come to PyCon DC 2005 http://www.pycon.org/ > Steve Holden http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
SOLVED: passing lists
It turns out that the function call was passing arguments in a different order than they were being received. Thanks, everyone, for your help. earl -- http://mail.python.org/mailman/listinfo/python-list
There's GOT to be a better way!
I'm writing my first program where I call custom modules. The 'global' command doesn't seem to apply, so how do I change a variable internally in a module without passing it down n layers, and then back out again? Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: There's GOT to be a better way!
On Thu, 2005-03-03 at 15:11, Steve Holden wrote: > Earl Eiland wrote: > > I'm writing my first program where I call custom modules. The 'global' > > command doesn't seem to apply, so how do I change a variable internally > > in a module without passing it down n layers, and then back out again? > > > You are correct in assuming that global isn't what you want - it really > means "global to the module namespace in which it appears". > > However, if two separate pieces of code can both reference the same > module then one can set an attribute in the module and the other can > reference it. Don't forget that when you import a module its name > becomes global within the importing module. Since a module is just a > glorified namespace, anything that can reference the module can read > and/or set that module's attributes. > > a.py: > > import something > something.x = "A value" > > b.py: > > import something > print something.x > > will print "A value" as long as a is imported before b. Right. That part I figured out. How does one function in an imported module access a variable in the same module? module.py def A(): test = 1 for x in range(10): B() def B(): test = test + 1 main.py import module module.A() This will fail, unless test is passed and returned. -- http://mail.python.org/mailman/listinfo/python-list
Re: There's GOT to be a better way!
On Thu, 2005-03-03 at 16:43, Steve Holden wrote: > Earl Eiland wrote: > > On Thu, 2005-03-03 at 15:11, Steve Holden wrote: > > > >>Earl Eiland wrote: > >> > >>>I'm writing my first program where I call custom modules. The 'global' > >>>command doesn't seem to apply, so how do I change a variable internally > >>>in a module without passing it down n layers, and then back out again? > >>> > >> > >>You are correct in assuming that global isn't what you want - it really > >>means "global to the module namespace in which it appears". > >> > >>However, if two separate pieces of code can both reference the same > >>module then one can set an attribute in the module and the other can > >>reference it. Don't forget that when you import a module its name > >>becomes global within the importing module. Since a module is just a > >>glorified namespace, anything that can reference the module can read > >>and/or set that module's attributes. > >> > >>a.py: > >> > >>import something > >>something.x = "A value" > >> > >>b.py: > >> > >>import something > >>print something.x > >> > >>will print "A value" as long as a is imported before b. > > > > Right. That part I figured out. How does one function in an imported > > module access a variable in the same module? > > > > module.py > > def A(): > global test > > test = 1 > > for x in range(10): B() > > > > def B(): > global test > > test = test + 1 > > > > > > main.py > > import module > > module.A() > print module.test > > > > > > This will fail, unless test is passed and returned. > > I thought I tried that, and it didn't work. I must have made some other mistake. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: There's GOT to be a better way!
On Thu, 2005-03-03 at 16:46, Steven Bethard wrote: > Earl Eiland wrote: > > module.py > > def A(): > > test = 1 > > for x in range(10): B() > > > > def B(): > > test = test + 1 > > > > > > main.py > > import module > > module.A() > > > > This will fail, unless test is passed and returned. > > (Sorry if this sent twice. It wasn't appearing for me the first time.) > > You can use global here, though I wouldn't advise it. > > -- module.py -- > def A(): > global test > test = 1 > for x in range(10): > B() > def B(): > global test > test = test + 1 > --- > > py> import module > py> module.A() > py> module.test > 11 > > This looks like it might be simpler with a class, e.g.: > > -- module.py -- > class A(object): > def __init__(self): > self.test = 1 > for x in range(10): > self.B() > def B(self): > self.test += 1 > --- > > py> import module > py> a = module.A() > py> a.test > 11 > > STeVe Guess I'm just gonna have to break down and figure out how to work with classes! -- http://mail.python.org/mailman/listinfo/python-list
autoexecution in Windows
How does one make a Python program auto-execute in Windows? Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: autoexecution in Windows
In Linux, if I make the first line #!/path/to/Python, all I have to do to execute the program is type ./FileName (assuming my pwd is the same as FileName). what's the Windows equivalent? Earl On Mon, 2005-03-07 at 13:36, F. Petitjean wrote: > Le Mon, 07 Mar 2005 13:25:35 -0700, Earl Eiland a Ãcrit : > > How does one make a Python program auto-execute in Windows? > > > > Earl > > > write a virus ? :-) > > What do you mean by  auto-execute  ? > > Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: autoexecution in Windows
O.K. I stand corrected. "auto-execute is the wrong term. Earl On Mon, 2005-03-07 at 14:03, rbt wrote: > Earl Eiland wrote: > > How does one make a Python program auto-execute in Windows? > > > > Earl > > > > No program (python or other) can just arbitrarily execute. A user has to > click it or a cron-like utility (Task Scheduler) has to execute it at a > set time. registry entries (such as run) can execute programs too. Also, > proper Windows services can be configured to start at boot. > > Again, nothing can just arbitrarily execute. If it could, viruses would > be a *nightmare* -- http://mail.python.org/mailman/listinfo/python-list
capturing text from a GUI window
Anyone know how to capture text from GUI output? I need to process information returned via a GUI window. Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: capturing text from a GUI window
On Tue, 2005-03-08 at 14:27, [EMAIL PROTECTED] wrote: > Earl Eiland wrote: > > Anyone know how to capture text from GUI output? I need to process > > information returned via a GUI window. > > > > Earl > > Assuming Windows, then these guys have an interesting tool: > http://www.skesoft.com/textcatch.htm > It's not free, but you can try it before you buy it. > You will need COM to control it from Python. This sounds like just what I need. What is COM, and where do I get it? (I'm really a Linux guy. I don't ken the mysteries of Window very well.) earl -- http://mail.python.org/mailman/listinfo/python-list
executing non-Python conde
I need to repeatedly execute an .exe program, changing the command line arguments, and log the output. My search of Python documentation and O'Reilly texts hasn't uncovered how I do this. Both exec and execfile seem to only run Python code. Also, neither seem to be able to pass parameters. (Although there is a reference to global and local dictionaries that I don't understand.) Surely there is a way to do this! Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
Re: executing non-Python conde
So where do I find win32process. It's not a builtin (at least import win32process fails) A search of python.org fails. A search of sourceforge fails. A google search brings up lots of stuff, but I didn't find the module. Earl Eiland On Fri, 2005-03-11 at 09:02, Larry Bates wrote: > Earl Eiland wrote: > > I need to repeatedly execute an .exe program, changing the command line > > arguments, and log the output. > > > > My search of Python documentation and O'Reilly texts hasn't uncovered > > how I do this. Both exec and execfile seem to only run Python code. > > Also, neither seem to be able to pass parameters. (Although there is a > > reference to global and local dictionaries that I don't understand.) > > > > Surely there is a way to do this! > > > > Earl Eiland > > > os.system() or win32process.CreateProcess() depending on how much > control you want and/or if it is a Windows GUI .exe. > > Larry Bates -- http://mail.python.org/mailman/listinfo/python-list
blocking a program until a non-Python process terminates
I'm running an .exe in Python, using subProcess.Popen. The executable writes data to a file I process later on in the program. Unfortunately, my program returns the error "no such file...". How do I block execution until the external executable terminates? Earl -- http://mail.python.org/mailman/listinfo/python-list
error sending path to Win OS
os.path.getsize(Inputdirectory + '\\' + Filename) works, but os.path.getsize(Inputdirectory + '\\' + Filename.split('.') + '.ext') Fails reporting "no such file or directory InputDirectory\\Filename.ext". os.path.getsize(Inputdirectory + r'\' + Filename.split('.') + '.ext') generates a syntax error. Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
Re: error sending path to Win OS
A couple of you commented that I should be using os.path.join. Accordingly, I rewrote my code. Unfortunately, I still have the same problem. the following code snippet Results.SetOriginal(os.path.getsize(os.path.join(InputDirectory , x))) y = str(x.split('.')[0]) + '.rk' print InputDirectory, y raw_input() Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y))) is executed from the command line with C:\Documents and Settings\eeiland\Desktop> ..\Thesis\Plan2\Compressor.py Test_Data\ Test_Output\Results Test_Data\ Book1.rk, where InputDirectory (in the above snippet) = 'Test_Data\' (I've also tried 'Test_Data', with the same results). x (in the above snippet) is an element of the list generated by os.listdir(InputDirectory). Output upon execution is as follows: Test_Data\ Book1.rk Traceback (most recent call last): File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py", line 60, in ? Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y))) File "C:\Python24\lib\ntpath.py", line 229, in getsize return os.stat(filename).st_size OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.rk' What am I doing wrong? Earl On Sat, 2005-03-12 at 15:16, Michael Hoffman wrote: > Earl Eiland wrote: > > os.path.getsize(Inputdirectory + '\\' + Filename) works, but > > os.path.getsize(Inputdirectory + '\\' + Filename.split('.') + '.ext') > > Fails reporting "no such file or directory > > InputDirectory\\Filename.ext". > > No, that should be a TypeError. This will be easier if you copy and > paste your Python session instead of making stuff up. > > > os.path.getsize(Inputdirectory + r'\' + Filename.split('.') + '.ext') > > generates a syntax error. > > 'r"\" is not a valid string literal (even a raw string cannot end in an > odd number of backslashes). Specifically, a raw string cannot end in a > single backslash (since the backslash would escape the following quote > character). Note also that a single backslash followed by a newline is > interpreted as those two characters as part of the string, not as a > line continuation.' > > http://docs.python.org/ref/strings.html > -- > Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: error sending path to Win OS
A couple of you commented that I should be using os.path.join. Accordingly, I rewrote my code. Unfortunately, I still have the same problem. the following code snippet Results.SetOriginal(os.path.getsize(os.path.join(InputDirectory , x))) y = str(x.split('.')[0]) + '.rk' print InputDirectory, y raw_input() Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y))) is executed from the command line with C:\Documents and Settings\eeiland\Desktop> ..\Thesis\Plan2\Compressor.py Test_Data\ Test_Output\Results Test_Data\ Book1.rk, where InputDirectory (in the above snippet) = 'Test_Data\' (I've also tried 'Test_Data', with the same results). x (in the above snippet) is an element of the list generated by os.listdir(InputDirectory). Output upon execution is as follows: Test_Data\ Book1.rk Traceback (most recent call last): File "C:\Documents and Settings\eeiland\Thesis\Plan2\Compressor.py", line 60, in ? Results.SetArchive(os.path.getsize(os.path.join(InputDirectory, y))) File "C:\Python24\lib\ntpath.py", line 229, in getsize return os.stat(filename).st_size OSError: [Errno 2] No such file or directory: 'Test_Data\\Book1.rk' What am I doing wrong? Earl On Sat, 2005-03-12 at 15:16, Michael Hoffman wrote: > Earl Eiland wrote: > > os.path.getsize(Inputdirectory + '\\' + Filename) works, but > > os.path.getsize(Inputdirectory + '\\' + Filename.split('.') + '.ext') > > Fails reporting "no such file or directory > > InputDirectory\\Filename.ext". > > No, that should be a TypeError. This will be easier if you copy and > paste your Python session instead of making stuff up. > > > os.path.getsize(Inputdirectory + r'\' + Filename.split('.') + '.ext') > > generates a syntax error. > > 'r"\" is not a valid string literal (even a raw string cannot end in an > odd number of backslashes). Specifically, a raw string cannot end in a > single backslash (since the backslash would escape the following quote > character). Note also that a single backslash followed by a newline is > interpreted as those two characters as part of the string, not as a > line continuation.' > > http://docs.python.org/ref/strings.html > -- > Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
program hangs when external process crashes
I'm executing WinRK.exe in a loop using the following code: for x in Files: Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set compression_method ppmz -setg include_paths none -add ' + os.path.join(InputDirectory, x) + ' -apply -quit' PROC = subprocess.Popen(Command_String) PROC.wait() Occasionally, WinRK crashes, and this program hangs at PROC.wait(). What can I do about this? Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
program hangs when external process crashes
I'm executing WinRK.exe in a loop using the following code: for x in Files: Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set compression_method ppmz -setg include_paths none -add ' + os.path.join(InputDirectory, x) + ' -apply -quit' PROC = subprocess.Popen(Command_String) PROC.wait() Occasionally, WinRK crashes, and this program hangs at PROC.wait(). What can I do about this? Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
subprocess 'wait' method causes .py program to hang.
I calling a Windows executable with PROC = subprocess.Popen('...'), and blocking further python execution until the process terminates with PROC.wait(). Occasionally, something unusual happens with the subprocess, and it fails without terminating the process. When this happens, my Python program doesn't detect the error condition, and hangs. What can I do about this? Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
python versions of perl modules
I need to process some tcpdump files. PERL has Net::Pcap and NetPacket, but I would rather work in PYTHON. Do PYTHON equivialnts of these two modules exist? Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
python versions of perl modules
I need to process a tcpdump file. PERL has Net::Pcap and NetPacket for this purpose. What does PYTHON have? I haven't found anything. Earl Eiland -- http://mail.python.org/mailman/listinfo/python-list
possible bug?
I've been having trouble with a program hanging when using the subprocess modules "wait()" method. Replacing it with with a loop that used "poll()" solved the problem. Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
I'm running the following code on Windows 2000, 5.00.2195: for x in Files: Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set compression_method ppmz -setg include_paths none -add ' + os.path.join(InputDirectory, x) + ' -apply -quit' PROC = subprocess.Popen(Command_String) PROC.wait() ... # process WinRK output This hangs occasionally, and is not repeatable - it never hangs on the same file. Replacing the PROC.wait() command with the loop while PROC.poll() == None: time.sleep(1) has not hung on approximately 7,000 calls to WinRK. Earl On Tue, 2005-03-22 at 09:35, Jeff Epler wrote: > On Tue, Mar 22, 2005 at 07:16:11AM -0700, Earl Eiland wrote: > > I've been having trouble with a program hanging when using the > > subprocess modules "wait()" method. Replacing it with with a loop that > > used "poll()" solved the problem. > > Please include an example, and more information about what platforn you're > using > This simple program worked fine for me on Linux with Python 2.4: > # > import subprocess, time > > s = subprocess.Popen(['sleep', '2']) > while 1: > time.sleep(.1) > if s.poll() is not None: break > print "polling wait done", s.returncode > > s = subprocess.Popen(['sleep', '2']) > s.wait() > print "blocking wait done", s.returncode > # > > Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
I'm running ActivePython PythonWin 2.4, and get the error message"'AributeError: 'module' object has no attribute 'SIGALRM'". The example provided in the ActivePython documents use signal.SIGALRM, so I'm not sure what's going on... Earl On Tue, 2005-03-22 at 12:43, Jeff Epler wrote: > I wrote a program to use subprocess.Popen 1 times, and never had > .wait() hang. If this is a bug, it may be Windows specific. > > Here's the program I ran: > #- > import subprocess, signal > def timeout(*args): > print "Timed out waiting on", i > raise SystemExit, 1 > > signal.signal(signal.SIGALRM, timeout) > > for i in xrange(1): > signal.alarm(5) > subprocess.Popen(['/bin/true']).wait() > if i % 100 == 0: print "done with", i > print "done!" > #- > > If the wait method ever hangs, the signal handler shuld be invoked. On > Unix, "/bin/true" is a very simple program that does nothing, so it's > virtually guaranteed to run in less than 5 seconds. On Windows, maybe > you want something like subprocess.popen('cmd.exe /c rem') as a command > that will do nothing and terminate quickly. What happens if you run my > program with that change to the Popen line? > > Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
Well, your program ran successfully. Perhaps WinRK is not well behaved. How can a process terminate in such a way that poll() can read it, but wait() won't? Earl On Tue, 2005-03-22 at 13:49, Jeff Epler wrote: > hm, I guess SIGALRM doesn't exist on Windows. You can run the program > without the 'signal.signal' line or the 'signal.alarm' line, and you'll > be stuck with a hung Python if subprocess.Popen exhibits the bug. > > Jeff -- http://mail.python.org/mailman/listinfo/python-list
Re: possible bug?
There may be different ways to code it. This works. The problem is that occasionally somehow, WinRK terminates without terminating the process, or at least Python doesn't pick up the return code. It turns out that using poll() instead of wait() only reduces the error frequency, and allows me to recover from the failure. It doesn't eliminate it. Earl On Thu, 2005-03-24 at 00:16, Tim Roberts wrote: > Earl Eiland <[EMAIL PROTECTED]> wrote: > > >I'm running the following code on Windows 2000, 5.00.2195: > > > >for x in Files: > > Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + > > That can't be right. You need either > Command_String = 'C:\\Program Files\\WinRK\\WinRK.exe -create ' + > or > Command_String = r'C:\Program Files\WinRK\WinRK.exe -create ' + > -- > - Tim Roberts, [EMAIL PROTECTED] > Providenza & Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
terminating an inactive process
I'm running a PyWin program that executes another program using subprocess.Popen(). Unfortunately, this other program isn't well behaved, and frequently terminates without terminating its process. After this happens enough times, all my memory is tied up, and the machine crashes. Using subprocess.poll(), I can keep my program from hanging, by timing out the process, and starting anew. This still leaves the previous process hogging memory. How do I kill the old process in Windows? Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: There's GOT to be a better way!
On Thu, 2005-03-03 at 16:43, Steve Holden wrote: > Earl Eiland wrote: > On Thu, 2005-03-03 at 15:11, Steve Holden wrote: > > Earl Eiland wrote: > > I'm writing my first program where I call custom modules. The 'global' > command doesn't seem to apply, so how do I change a variable internally > in a module without passing it down n layers, and then back out again? > > > You are correct in assuming that global isn't what you want - it really > means "global to the module namespace in which it appears". > > However, if two separate pieces of code can both reference the same > module then one can set an attribute in the module and the other can > reference it. Don't forget that when you import a module its name > becomes global within the importing module. Since a module is just a > glorified namespace, anything that can reference the module can read > and/or set that module's attributes. > > a.py: > > import something > something.x = "A value" > > b.py: > > import something > print something.x > > will print "A value" as long as a is imported before b. > > Right. That part I figured out. How does one function in an imported > module access a variable in the same module? > > module.py > def A(): > global test > test = 1 > for x in range(10): B() > > def B(): > global test > test = test + 1 > > > main.py > import module > module.A() > print module.test > > > This will fail, unless test is passed and returned. > > I thought I tried that, and it didn't work. I must have made some other mistake. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
error using process module Process class
When executing the following code snippet import process ... ... for x in Files: Command_String = 'C:\Program Files\WinRK\WinRK.exe -create ' + os.path.join(InputDirectory, os.path.splitext(x)[0]) + ' -set compression_method ppmz -setg include_paths none -add ' + os.path.join(InputDirectory, x) + ' -apply -quit' PROC = process.Process(Command_String) PROC.wait() from the command line C:\Documents and Settings\eeiland\Desktop>Thesis_Programs\Compressor2.py Test_Da ta\sliceX12 Test_Output\Test generates the following error: Traceback (most recent call last): File "C:\Documents and Settings\eeiland\Desktop\Thesis_Programs\Compressor2.py ", line 61, in ? PROC = process.Process(Command_String) File "C:\Python24\Lib\site-packages\process.py", line 839, in __init__ self._startOnWindows() File "C:\Python24\Lib\site-packages\process.py", line 913, in _startOnWindows cmd = _whichFirstArg(cmd, self._env) File "C:\Python24\Lib\site-packages\process.py", line 303, in _whichFirstArg import which ImportError: No module named which -- http://mail.python.org/mailman/listinfo/python-list
command string good in subprocess.Popen(string) fails in process.Process(string)
The command string consists of "filename.exe instruction1 instruction2 ..." It works in subprocess, but in process, returns the error "can't find the file instruction1". How do I pass command line instructions in process.Process? I tried a list ['filename.exe', 'instruction1 instruction2 ...'] with the same result. If you're wondering why I'm switching, it's because I'm working with a poorly behaved 3rd party program that causes a severe memory leak, and I need the process modules timed "wait(n)" method (or write my own). Earl -- http://mail.python.org/mailman/listinfo/python-list
Re: command string good in subprocess.Popen(string) fails in process.Process(string)
from Trent Mick [EMAIL PROTECTED]: "You might be able to use or borrow code from my process.py module. process.py is very similar to Python 2.4's subprocess. It provides a ProcessOpen class (similar to subprocess' Popen). A ProcessOpen instance has wait() and kill() methods that work fine on Windows. Under the hood they are using the Win32 API WaitForSingleObject() and TerminateProcess() functions." http://starship.python.net/~tmick/"; On Mon, 2005-05-16 at 07:27, Peter Hansen wrote: > Earl Eiland wrote: > > The command string consists of "filename.exe instruction1 instruction2 > > ..." It works in subprocess, but in process, returns the error "can't > > find the file instruction1". > > > > How do I pass command line instructions in process.Process? I tried a > > list ['filename.exe', 'instruction1 instruction2 ...'] with the same > > result. > > Where are you getting this "process" module from? It's not standard: > > c:\>python > Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32 > >>> import process > Traceback (most recent call last): >File "", line 1, in ? > ImportError: No module named process > > > -Peter -- http://mail.python.org/mailman/listinfo/python-list