'Q : run a python function in Django project but output repeat result
I want to detect the number of files when run a django project.But there are two output results in terminal .
def fileChecker(path):
print('Child process %s.' % os.getpid())
dirs = os.listdir(path)
size = len(dirs)
while True :
tdirs = os.listdir(path)
if len(tdirs) > size :
print( 'folder contains %s files '%( len(tdirs) ) )
size = len(tdirs)
dirs = tdirs
def main():
"""Run administrative tasks."""
print('Child process %s.' % os.getpid())
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'parkSystem.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
print('Parent process %s.' % os.getpid())
p1 = Process( target=main )
p2 = Process( target=fileChecker, args=('.\\pictures\\car_img',))
p1.start()
p2.start()
p1.join()
p2.join()
the terminal like this : enter image description here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
