11from typing import TYPE_CHECKING , Optional
2-
2+ from threading import Thread
33from .basic import Basic
44
55from pieces ._vendor .pieces_os_client .models .allocation_status_enum import AllocationStatusEnum
@@ -53,19 +53,19 @@ def _on_login_connect(self):
5353 thread: The thread handling the login process.
5454 timeout: The maximum time to wait for the login process.
5555 """
56- self .connect (True )
57-
56+ self .connect ()
5857 def login (self , connect_after_login = True , timeout = 120 ):
5958 """
6059 Logs the user into the OS and optionally connects to the cloud.
6160
6261 Args:
63- connect_after_login: A flag indicating if the user should connect to the cloud after login (default is True).
64- timeout: The maximum time to wait for the login process (default is 120 seconds).
62+ connect_after_login: A flag indicating if the user should connect to the cloud after login (default is True).
63+ timeout: The maximum time to wait for the login process (default is 120 seconds).
6564 """
66- thread = self .pieces_client .os_api .sign_into_os (async_req = True )
65+ thread = Thread (target = self .pieces_client .os_api .sign_into_os )
66+ thread .start ()
6767 if connect_after_login :
68- user = thread .get (timeout )
68+ user = thread .join (timeout )
6969 self .user_profile = user
7070 self ._on_login_connect ()
7171
@@ -84,8 +84,20 @@ def connect(self, async_req = False):
8484 """
8585 if not self .user_profile :
8686 raise PermissionError ("You must be logged in to use this feature" )
87- self .on_user_callback (self .user_profile , True ) # Set the connecting to cloud bool to true
88- self .pieces_client .allocations_api .allocations_connect_new_cloud (self .user_profile ,async_req = async_req )
87+ self .on_user_callback (
88+ self .user_profile , True
89+ ) # Set the connecting to cloud bool to true
90+ if async_req :
91+ thread = Thread (
92+ target = self .pieces_client .allocations_api .allocations_connect_new_cloud ,
93+ args = (self .user_profile ,),
94+ )
95+ thread .start ()
96+ else :
97+ self .pieces_client .allocations_api .allocations_connect_new_cloud (
98+ self .user_profile
99+ )
100+
89101
90102 def disconnect (self ):
91103 """
0 commit comments