It should be safe, but it does make more sense to do it in the mainloop.  Also, if done from the main loop we do have the option of rotating the file (with a lock) right at the moment, instead of waiting for the next write.