in reply to Threads, Tk, Time, oh my!

It seems that in your code, the only (relevant?) use of Time::Piece is in PM::CB::Communication for the timestamp. But you only use Time::Piece there to parse the incoming create time and convert it to some other string. This should be fairly safe, but maybe mod:://Time::Piece runs afoul of setting/resetting timezones or locale data between threads.

Does the problem go away if you switch from Time::Piece to POSIX::strftime and manually convert the string (resp. replace the string with a hardcoded dummy)?

if (@nodes) { $self->{to_gui}->enqueue( [private => '<pm-cb-g>', 'Time::Piece'->strptime($_->{createtime}, '%Y%m%d%H%M%S') ->strftime('%Y-%m-%d %H:%M:%S'), "New node: [id://$_->{node_id}|" . $_->textContent =~ s/\n//r . '] by [id://' . "$_->{author_user}|$_->{authortitle} +]", NOT_DELETABLE]) for grep ! exists $nodes{ $_->{node_id} }, reverse @no +des; @nodes{ map $_->{node_id}, @nodes} = (); }

Alternatively, you can maybe try to run your code with $ENV{LANG}='C' or $ENV{LC_TIME}='C', or whatever is used to reset the information there... If that "helps", this points towards a locale handling bug/conflict between threads and Time::Piece, but that's where my ideas end.

Replies are listed 'Best First'.
Re^2: Threads, Tk, Time, oh my!
by choroba (Cardinal) on May 07, 2026 at 09:45 UTC
    > the only (relevant?) use of Time::Piece is in PM::CB::Communication for the timestamp

    Unfortunately, there's far more of Time::Piece in PM::CB::GUI.

    Thanks for the recommendations and tips, I'll experiment with them and see.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

      Aah - yeah, this part looks fishy, or at least prone to trigger thread+locale-based conflicts:

      if (defined $time) { local $ENV{TZ} = 'America/New_York'; my $est = Time::Piece::localtime()->tzoffset; $time = 'Time::Piece'->strptime($time, '%Y-%m-%d %H:%M:%S') - $est + $tzoffset; } else {

      Manipulating the timezone is weirdly(?) not threadsafe, or at least that's what I remember from some Perl tickets.

      Update: You could calculate the timezone once at program startup, that could eliminate the switching of the timezone within a thread.