Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
threading across imports
so the problem i am having is that im trying to get my text from a main .py file and with txt being at the end of this line here t = threading.Thread(target=reminder(txt))
it does not work properly it should just be target = reminder with that it works fine only if i get my text from this file basically what im asking is how can i get text = input(cmd: ) from my main file with out having circular import issues and get the threading working properly also so in short i need to avoid having the txt argument in the reminder function but still being able to pass the text from my file through the function so it knows what it is looking for

import time
import datetime
import re
import threading

def find_time_in_text(txt):
    pattern = r"(\d+)(?::(\d+))?\s*([ap]\.m\.)"

    m =, txt)
    if m:
        hour, minute, am_pm = m.groups()
        time_ = f"{hour}:{minute or 0} {am_pm}"
        return time_
        print("Couldn't find a time in the right format")

def reminder(txt):
    if "a.m." in txt or "p.m." in txt:
        get_time = find_time_in_text(txt)
        # Getting the time
        time_to_list = get_time.split()
        # this splits time to a list
        time_to_split = time_to_list[0]
        # This gets hour and minute
        split_time_ = time_to_split.split(":")
        # This splits hour and minutes
        hour = split_time_[0]
        minute = split_time_[1]
        am_pm_ = time_to_list[1]
        alarm_hour = int(hour)
        alarm_minutes = int(minute)
        am_pm = str(am_pm_)
        print(f"A reminder is set for: {alarm_hour}:{alarm_minutes} {am_pm}")
        if am_pm == 'p.m.':
            alarm_hour += 12
        elif alarm_hour == 12 and am_pm == 'a.m.':
            alarm_hour -= 12
        while True:
            if alarm_hour == and alarm_minutes ==
                print("\nIt's the time!")

    if "minute" in txt or "minutes" in txt:
        for s in txt.split():
            if s.isdigit():
                number = int(s)
                reminder2 = number * 60
                print(f"A reminder is set for {number} minutes from now.")

    elif "second" in txt or "seconds" in txt:
        for s in txt.split():
            if s.isdigit():
                number = int(s)
                reminder2 = number
                print(f"A reminder is set for {number} seconds from now.")


def thred(txt):
    threads = []
    for _ in range(1):
        t = threading.Thread(target=reminder(txt))
    for thread in threads:
t = threading.Thread(target=reminder(txt))
This is not how you pass arguments to a thread, This calls reminder(txt) and then tries to launch a tread using the return value which is None. In effect you are calling
t = threading.Thread(target=None)
You want to do this:
t = threading.Thread(target=reminder, args=(name,))
What does this have to do with imports?
ahh that worked thank you and because I have a while true loop in a different .py file where it gets an input information from. I didn't know you could add args to threading and it worked perfectly thank you so much!

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help wanted with python imports petros21 3 350 Apr-07-2021, 07:16 PM
Last Post: snippsat
Question How to include Modules not found (conditional imports) in my when I want to cff 0 411 Mar-17-2021, 11:57 AM
Last Post: cff
  refreshing imports seandepagnier 4 669 Sep-20-2020, 11:51 PM
Last Post: seandepagnier
  Multimode imports fine as script but not after compiling into exe chesschaser 0 450 Aug-13-2020, 01:28 PM
Last Post: chesschaser
  absolute imports between folders mikisDW 0 399 Aug-05-2020, 12:26 PM
Last Post: mikisDW
  Understanding the concept ( Modules , imports ) erfanakbari1 1 622 Nov-25-2019, 01:59 AM
Last Post: Larz60+
  How Do I Get the IDE to Find My Imports petec 18 3,926 Feb-24-2019, 02:50 AM
Last Post: petec
  When are imports loaded? MuntyScruntfundle 2 975 Feb-10-2019, 03:47 PM
Last Post: ichabod801
  Nested Imports CanadaGuy 4 1,294 Nov-08-2018, 12:20 AM
Last Post: CanadaGuy
  check imports Viesturs 6 1,896 Jul-28-2018, 09:58 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020