import logging
import threading
import time
def thread_Apellido(name, inicio=1, fin=1):
for x in range(inicio, fin):
print (f"{name} Rodríguez {str(x)} años\n",end="")
nombres = ["Julio", "Javier", "Eladio", "Jose", "Manuel"]
hilos = list()
for n in nombres:
t = threading.Thread(target=thread_Apellido, args=(n,), kwargs={'inicio':5, 'fin':8})
hilos.append(t)
t.start()
PS C:\PROGRAMACION\PYTHON\T2.HILOS> c:; cd 'c:\PROGRAMACION\PYTHON\T2.HILOS'; & 'C:\Users\juanj\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\juanj\.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '57176' '--' 'C:\PROGRAMACION\PYTHON\T2.HILOS\hilo6.py'
Julio Rodríguez 5 años
Javier Rodríguez 5 años
Julio Rodríguez 6 años
Javier Rodríguez 6 años
Julio Rodríguez 7 años
Javier Rodríguez 7 años
Eladio Rodríguez 5 años
Eladio Rodríguez 6 años
Eladio Rodríguez 7 años
Jose Rodríguez 5 años
Jose Rodríguez 6 años
Jose Rodríguez 7 años
Manuel Rodríguez 5 años
Manuel Rodríguez 6 años
Manuel Rodríguez 7 años
PS C:\PROGRAMACION\PYTHON\T2.HILOS> c:; cd 'c:\PROGRAMACION\PYTHON\T2.HILOS'; & 'C:\Users\juanj\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\juanj\.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '57198' '--' 'C:\PROGRAMACION\PYTHON\T2.HILOS\hilo6.py'
Julio Rodríguez 5 años
Julio Rodríguez 6 años
Javier Rodríguez 5 años
Julio Rodríguez 7 años
Javier Rodríguez 6 años
Javier Rodríguez 7 años
Eladio Rodríguez 5 años
Eladio Rodríguez 6 años
Eladio Rodríguez 7 años
Jose Rodríguez 5 años
Jose Rodríguez 6 años
Jose Rodríguez 7 años
Manuel Rodríguez 5 años
Manuel Rodríguez 6 años
Manuel Rodríguez 7 años
PS C:\PROGRAMACION\PYTHON\T2.HILOS>
Crea un programa en Python que trabaje con hilos de la siguiente manera: hilo A: encargado de hacer un escraping sobre una página web; Hilo B: busca enlaces a otras páginas a partir de los datos que le pasa el hilo A; hilo C: Guarda la información del scraping realizada por el hilo A en un fichero. hilo D: Guarda en base de datos (MySql) los enlaces obtenidos por el hilo B y se los vuelve a pasar al hilo A.
Crea una estructura de páginas web en un servidor local (Xampp por ejemplo). index.html enlazará con 1.html y a su vez 1.html enlazará con 2.html, y 2.html también tendrá un enlace para ir a 1.html, tanto 1.html, como 2.html tendrán un enlace que pondrá «inicio» e irá a index.html. La url que tendrán que pasarle al programa será algo así como http://localhost/thread4 que contendrá los 3 ficheros html
Crea un proyecto Git «04-thread» y sube tu aplicación al repositorio de clase.. Tu proyecto debe incluir el fichero README en formato Markdown con el resultado de la ejecución y una explicación del funcionamiento.
Ejecuta | Usar sólo en caso de emergencia o una vez hayas resuelto el ejercicio.
index.html
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Inicio</title>
</head>
<BODY>
<a href="1.html">Ir a página 1</a>
</BODY>
</html>
1.html
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Página 1</title>
</head>
<BODY>
<a href="2.html">Ir a página 2</a>
<br>
<a href="index.html">Volver</a>
</BODY>
</html>
2.html
<html lang="es">
<head>
<meta charset="UTF-8">
<title>Página 2</title>
</head>
<BODY>
<a href="1.html">Ir a página 1</a>
<br>
<a href="index.html">Volver</a>
</BODY>
</html>
base de datos (desde root):
CREATE DATABASE IF NOT EXISTS thread4;
CREATE USER 'thread4'@'localhost' IDENTIFIED BY '1234';
GRANT ALL PRIVILEGES ON thread4.* TO 'thread4'@'localhost';
FLUSH PRIVILEGES;
crear tabla:
use thread4;
drop table if exists enlaces;
CREATE TABLE enlaces (
id INT NOT NULL AUTO_INCREMENT,
enlace VARCHAR(500) NOT NULL DEFAULT '0',
PRIMARY KEY (id),
UNIQUE INDEX indice_unico_enlace (enlace)
);
pip install mysql-connector-python
INSERT IGNORE ...