Deeply WEIRD Python 3.6 Problem

I’m running OpenSuse 15.5, with Python 3.6 installed. I have a little test gadget that was working fine a couple of weeks ago. I run it inside a terminal.

Yesterday evening, I ran it and it appeared to hang, but I had a weird-looking cross mouse cursor over the terminal. I clicked the mouse three times, and the program crashed with this error message:

./test.py: line 8: syntax error near unexpected token `"Hello, I'm running!"'
./test.py: line 8: `print( "Hello, I'm running!" )'

That’s not the really weird part. It also creates three PostScript screenshots of the terminal as it was just prior to starting the program. Three; and best of all, those three screenshot files have the names of my imported libraries!

The code is fine; I’ve run it on other versions of Linux today and it does as intended. I “touch” a file named “RELOAD,” I get the message and the file is deleted. Here’s the program:

import os.path
import sys
import time

print( "Hello, I'm running!" )
while 1:
    if os.path.isfile( "RELOAD" ):
        os.remove( "RELOAD" )
        print( "Got it! Reloading!" )
        print()
    time.sleep( 5 )

I wonder if a recent update to Python 3.6 messed up something?

openSUSE Leap 15.5 (Up to date) with python3.6

> python3.6
Python 3.6.15 (default, Sep 23 2021, 15:41:43) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
> cat test.py
import os.path
import sys
import time

print( "Hello, I'm running!" )
while 1:
    if os.path.isfile( "RELOAD" ):
        os.remove( "RELOAD" )
        print( "Got it! Reloading!" )
        print()
    time.sleep( 5 )

> python3.6 ./test.py 
Hello, I'm running!

No problem here.

Thanks! Like I said, the code worked as-is on another version of Linux (CentOS 7). I’ve stopped using os.path and have switched to pathlib (“from pathlib import Path”). That works fine on OpenSuse, so that tells me that something is wrong with the os.path module that has been installed.

What threw me was the fact that it was taking screenshots. I’m still not sure how that would even work, nor can I understand how it would create PostScript (NOT PDF, as I said above) files.

For those who care, this works as intended:

#!/usr/bin/python3
from pathlib import Path
import time

# Path
path = '/home/stephen/public_html/Routing/Working.py/RELOAD'
kill_me = '/home/stephen/public_html/Routing/Working.py/DIE'

path_obj = Path(path)
kill_obj = Path(kill_me)

while 1:
    print( "Hello, I'm running!" )
    if path_obj.exists():
        print( "The file is there!" )
        path_obj.unlink()
        print( "... but not anymore!" )
    else:
        print( "The file is missing!" )
    if kill_obj.exists():
        print( "Goodbye, cruel world!" )
        kill_obj.unlink()
        exit()
    time.sleep(5)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.