jdf / Processing.py-Bugs

A home for all bugs and feature requests about Python Mode for the Processing Development Environment.
41 stars 8 forks source link

Random failure to write to File objects, in OS X??? #226

Open liavkoren opened 6 years ago

liavkoren commented 6 years ago

This seems super duper weird, I know, but multiple variants of using file.write() seem to randomly and frequently fail for me. I've tried bothwith open('foo_test_file', 'w') as file: and file = open('foo_test_file', 'w'), and with calls both inside setup and draw, as well as verified that small test files that should have been written to disk can still be opened and have their contents read, even when they don't appear on disk.

Might this be a buffer in Java or Jython that needs to be flushed to disk?

One example:

def setup():
    for idx in range(20):
        filename = 'foobar' + str(idx)
        print(filename)
        file = open(filename, 'w')
        file.write('this is a test')
        file.close()

    filename = 'foobar0'
    file = open(filename)
    print(file.read())

def draw():
    filename = 'foobar0'
    file = open(filename)
    print(file.read())
    file.close()

I've run this sketch multiple times and did ls for the directory after each time, saw nothing, also used the Processing 'Show Sketch Folder' thing to double check.

system info:

OS X 10.12.5 PyMode 3037 P5 v3.3.7 app path: /Applications/Processing.app sketch path: /Users/liavkoren/Processing

liavkoren commented 6 years ago

Also, the save builtin does seem to be completely reliable.

liavkoren commented 6 years ago

O. I guess we're supposed to use createWriter?

jdf commented 6 years ago

I'm not sure where the current working directory is at processing runtime. That's where your files are likely to be.