brainrender icon indicating copy to clipboard operation
brainrender copied to clipboard

[BUG] log.log when running two kernels importing brainrender

Open harshk95 opened this issue 9 months ago • 1 comments

When attempting to import brainrender in two separate notebooks, the Path(path).unlink() in the init.py does not allow the log file to be deleted if another kernel is using the file.

It would be useful to generate another log file or just edit the current one (Currently we remove the unlink).

  • OS: Windows
  • Version 2.1.9

harshk95 avatar Feb 10 '25 14:02 harshk95

This seems like something we can probably fix. I'm curious as to the use case for running brainrender twice simultatenously though?

adamltyson avatar Feb 17 '25 14:02 adamltyson

I am coming back to this because this week I've been teaching a workshop on braian, and some students with Windows had this problem.

I'm curious as to the use case for running brainrender twice simultatenously though?

I have no use case for running two instances of brainrender, however setting up the logging directly on the __init__ file means that any other package that depends on brainrender will require access to $HOME/.brainglobe/brainrender/log.log.

In my case, the submodule braian.plot directly imports brainglobe_heatmap, which in turns imports brainrender a bunch of times. In this case, we don't directly ask to use brainrender, however it is setup every time.

It's funny how this doesn't happen on Linux. Does that mean that the logging from two notebooks can theoretically be conflicting?

Also: might be related to a discussion i had with @alessandrofelder but that I can't find anymore, unfortuantely. I was asking whether there was any plan to lighten the dependency on brainrender, iirc

carlocastoldi avatar Oct 23 '25 21:10 carlocastoldi

#428 makes the logs use datetime stamps to create unique log files (up to a maximum of 100). This should hopefully fix this issue. I've tested it both with brainrender and brainglobe-heatmap to make sure there are no weird interactions.

Interesting how it only happens on Windows! I would agree with your assumption that logging must have been conflicting, or we entered some undefined behaviour...

IgorTatarnikov avatar Oct 24 '25 09:10 IgorTatarnikov

super quick, thank you!

I don't have a chance to test it right away, but I saw that two of you did. Thanks again!

carlocastoldi avatar Oct 24 '25 12:10 carlocastoldi